我不能爲起始頁設定值(位置0)Viewpager位置0與使用onPageSelected(0)
我的意思是QuestionPagerAdapter.tv.setText( 「默認」)必須MainActivity的使用onPageSelected工作(INT位置不工作)情況0:但它給零點。但它工作位置> 0
PagerAdapter:
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);
}
}
MainActivity:
@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;
}
感謝您的回覆,我已經改變了代碼;刪除asynctask。只想爲起始頁面(位置0)設置一個值,但它會給出零點 – metemet06 2013-04-18 02:24:56