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
}
}
tengo este código allí ^^ ... más o menos toman directamente de http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/ ... Todavía estoy bastante nuevo en el mundo de Desarrollos android:/Android ViewPager findViewById que no trabaja - Siempre volver nula
Ahora estoy tratando de acceder a un control giratorio y algunos botones dentro de las "páginas". ¡Pero findViewById sigue devolviendo null!
Recuerdo que algo sobre el diseño no existe realmente dentro del código y tiene que ser inflado primero, lo que está sucediendo en la función instantiateItem(). Y es bastante obvio que va a la variable "ver". Pero cuando llamo al view.findViewById (R.id.light1_off);
que es un botón por cierto, siempre devuelve ZERO! Incluso me aseguré de que solo llamara cuando en realidad se estaba cargando la página. Pero no importa lo que hice, siempre sigue devolviendo un nulo y obtengo una desagradable excepción de nullpointer.
¿Podría alguien ayudarme aquí? Estoy casi sin ideas, y Google no es de ninguna ayuda, ya he estado en la página 5 en aproximadamente 10 términos de búsqueda diferentes.
Buen trabajo! Este fue un problema realmente frustrante. – Jackson
realmente fantástico trabajo! Muchas gracias – swati
¿Cómo accedemos al botón de la actividad principal? –