public class HSPTabletTestActivity extends Activity {
private class MyPagerAdapter extends PagerAdapter {
public int getCount() {
return 2;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.lighttab;
break;
case 1:
resId = R.layout.securitytab;
break;
}
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public void finishUpdate(View arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
// TODO Auto-generated method stub
}
@Override
public Parcelable saveState() {
// TODO Auto-generated method stub
return null;
}
@Override
public void startUpdate(View arg0) {
// TODO Auto-generated method stub
}
}
I have this code up there ^^ ... Pretty much taken directly from http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/ ... I'm still pretty new in the world of android developement :/
Now I'm trying to access a spinner control and some buttons inside the "pages". But findViewById keeps returning null!
I remember something about the layout doesn't exist really inside the code and has to be inflated first, which is happening in the instantiateItem() function. And it's pretty obvious that it's going into the "view" variable. But when I call view.findViewById(R.id.light1_off);
which is a button by the way, it is always returning ZERO! I even made sure it only called when it was actually that page being loaded. But no matter what I did, it always keep returning a null and I get a nasty nullpointer exception.
Could someone help me out here? I'm pretty much out of ideas, and Google isn't of any help, already been to page 5 on about 10 different search terms.