为此,我已经把头发拉了一天 - 我从 PagerAdapter 继承并从我的主要活动中调用了以下内容。问题是下面的测试总是返回null
。另外,我调试的时候发现MyPagerAdapter.java中的instantiateItem方法根本没有输入!是什么赋予了?
感谢我能得到的任何帮助。谢谢。
码头。
// For the paging swipes
MyPagerAdapter adapter = new MyPagerAdapter();
m_ViewPager = (ViewPager) findViewById(R.id.myfivepanelpager);
adapter.notifyDataSetChanged();
m_ViewPager.setAdapter(adapter);
m_ViewPager.setCurrentItem(2);
View test = m_ViewPager.getChildAt(2);
ListView theList = (ListView) test.findViewById(R.id.listView1);
MyPagerAdapter.java
public class MyPagerAdapter extends PagerAdapter {
public int getCount() {
return 5;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
//Log.d("Instantiate Item", null);
LayoutInflater inflater = (LayoutInflater) container.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//View view = null;
View view;
int resId = 0;
switch (position) {
case 0:
resId = R.layout.page1;
view = inflater.inflate(resId, null);
TextView txtView =(TextView)view.findViewById(R.id.textView1);
ListView lstView = (ListView)view.findViewById(R.id.listView1);
break;
case 1:
resId = R.layout.page2;
view = inflater.inflate(resId, null);
TextView txtView2 =(TextView)view.findViewById(R.id.textView2);
break;
case 2:
resId = R.layout.page3;
view = inflater.inflate(resId, null);
TextView txtView3 =(TextView)view.findViewById(R.id.textView3);
break;
case 3:
resId = R.layout.page4;
view = inflater.inflate(resId, null);
TextView txtView4 =(TextView)view.findViewById(R.id.textView4);
break;
case 4:
resId = R.layout.page5;
view = inflater.inflate(resId, null);
TextView txtView5 =(TextView)view.findViewById(R.id.textView5);
break;
default:
resId = R.layout.page1;
view = inflater.inflate(resId, null);
break;
}
((ViewPager) container).addView(view, 0);
return view;
}
@Override
public void destroyItem(ViewGroup arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}