我无法设置起始页的值(位置 0)
我的意思是 QuestionPagerAdapter.tv.setText("default") 必须在 MainActivity 的 onPageSelected(int position) case 0 中工作:但它给出了空点。但它适用于位置> 0
寻呼机适配器:
public class QuestionPagerAdapter extends PagerAdapter{
public static TextView tv;
@Override
public Object instantiateItem(View collection, int pos) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View page = inflater.inflate(R.layout.page_quiz, null);
tv = (TextView)page.findViewById(R.id.questionText);
}
}
主要活动:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
mPager = (ViewPager)findViewById(R.id.pager);
QuestionPagerAdapter mAdapter = new QuestionPagerAdapter();
mPager.setAdapter(mAdapter);
@Override
public void onPageSelected(int position) {
switch (position) {
case 0:
// QuestionPagerAdapter.tv.setText("default"); => doesnt works
break;
default:
QuestionPagerAdapter.tv.setText("default"); => works
break;
}