我希望能够在使用FragmentGridPagerAdapter
课程创建的片段中更新TextView的值,但我真的不知道如何实现这一点。< / p>
这是我打电话给我的班级创建片段的地方。
final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
pager.setAdapter(new SGridPagerAdapter(this, getFragmentManager(), data));
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager);
这是我的课程,扩展了FragmentGridPagerAdapter
。
public class SGridPagerAdapter extends FragmentGridPagerAdapter {
String[] mData;
private final Context mContext;
private static final String TAG = SGridPagerAdapter.class.getSimpleName();
public SGridPagerAdapter(Context ctx, FragmentManager fm, String[] data) {
super(fm);
mData = data;
mContext = ctx;
}
@Override
public Fragment getFragment(int row, int column) {
Log.d(TAG, "row : " + row + "/columns : " + column);
Fragment f = null;
switch(column) {
case 0 :
f = cardFragment(R.string.welcome_title, R.string.welcome_text);
break;
case 1 :
f = SelectionFragment.newInstance("secondFragment");
break;
}
return f;
}
private Fragment cardFragment(int titleRes, int textRes) {
Resources res = mContext.getResources();
CardFragment fragment = CardFragment.create(res.getText(titleRes), res.getText(textRes));
// Add some extra bottom margin to leave room for the page indicator
//fragment.setCardMarginBottom(
// res.getDimensionPixelSize(R.dimen.card_margin_bottom));
return fragment;
}
@Override
public int getRowCount() {
return 1;//mData.length;
}
@Override
public int getColumnCount(int row) {
return mData.length;
}
}