我希望我的浏览寻呼机每次都拨打onCreate
所以使用以下代码:
@Override
public void setUserVisibleHint(boolean isVisibleToUser)
{
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser && isChanged())
{
isChanged = false;
getFragmentManager().beginTransaction().detach(this).attach(this).commit();
viewPagerUpdatedInterface.viewPagerUpdated(); // inteface called in main method this will adapter.notifyDataSetChanged();
}
}
在这里,我能够看到我需要在日志中更新的字符串的正确值,但屏幕上没有显示相同的值。
我的适配器类如下:
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}