Android: FragmentAdapter and pageview do not update the view
Posted
by
user1240937
on Stack Overflow
See other posts from Stack Overflow
or by user1240937
Published on 2012-06-16T09:19:32Z
Indexed on
2012/06/22
15:16 UTC
Read the original article
Hit count: 252
My trouble is: when i get new data, my viewpager that use my custom adapter do not update view. I discovered that many programmer got same bug, so i tried a lot of suggestion but no way works for me. So tired. One more time, read my source and help me understand why i fail with updating view pleaseee! Here is my FragmentAdapter:
private class SwipeyTabsPagerAdapter extends FragmentPagerAdapter implements
SwipeyTabsAdapter {
private final Context mContext;
private String[] datas;
public SwipeyTabsPagerAdapter(Context context, FragmentManager fm, String[] ds) {
super(fm);
this.mContext = context;
datas=ds;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public Fragment getItem(int position) {
Log.e("new item:", datas[position]);
return SwipeyTabFragment.newInstance(datas[position]);
}
@Override
public int getCount() {
return datas.length;
}
public TextView getTab(final int position, SwipeyTabs root) {
TextView view = (TextView) LayoutInflater.from(mContext).inflate(
R.layout.swipey_tab_indicator, root, false);
view.setText(datas[position]);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mViewPager.setCurrentItem(position);
}
});
return view;
}
}
and here is where i set adapter:
SwipeyTabsPagerAdapter adapter = new SwipeyTabsPagerAdapter(getApplicationContext(), getSupportFragmentManager(),dicts);
mViewPager.setAdapter(adapter);
mTabs.setAdapter(adapter);
mViewPager.getAdapter().notifyDataSetChanged();
By logcat, can see clearly that: only first time, newItem be processed, so view can not be update.
© Stack Overflow or respective owner