0
我正在使用視圖尋呼機。在這個視圖尋呼機我有3頁。當我運行應用程序。查看尋呼機創建左側中心和右側片段實例,並調用所有生命週期方法。我的問題是,當我選擇中間頁面時,我需要顯示一些數據。但我無法獲得任何回調方法。請幫幫我。提前致謝。如何在Android中刷新ViewPager的中間頁面的數據
適配器
public class ViewPagerFragmentPageAdapter extends FragmentPagerAdapter {
Context mContext;
public ViewPagerFragmentPageAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return BusinessCategoryFragment.getInstance();
case 1:
return FavoriteFragment.getInstance(mContext.getResources().getString(R.string.favorite));
case 2:
return RecentFragment.getInstance(mContext.getResources().getString(R.string.recent));
default:
return BusinessCategoryFragment.getInstance();
}
}
@Override
public int getCount() {
return 3;
}
}
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewFragmentPageAdapter = new ViewPagerFragmentPageAdapter(
HomeActivity.this, getSupportFragmentManager());
mViewPager.setAdapter(mViewFragmentPageAdapter);
http://stackoverflow.com/questions/12650810/how-to-know-which-fragment-is-currently-selected-in-a-viewpager – dhke
中間頁的可能的複製是'Fragment'本身與其他'片段'分離。所以如果你想刷新這個片段,不管你對這個片段做什麼,只有那個fragmetn會受到影響 – hrskrs