cased
20/03/14, 17:20:54
Buenas:
Tengo un problema y es que el metodo TabHost.setup() me detiene el programa cuando le toca ejecutar a la actividad a la que esta asociada, os dejo el código a ver si alguien puede echarme una manilla. :-)
public class Prueba extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fisicascnp);
Resources res = getResources();
TabHost tabs=(TabHost)findViewById(android.R.id.tabhost);.
tabs.setup(); //Aqui es donde salta la ejecución!!!!!!!!!
TabHost.TabSpec spec=tabs.newTabSpec("mitab1");
spec.setContent(R.id.tab1);
spec.setIndicator("TAB1",
res.getDrawable(android.R.drawable.ic_btn_speak_no w));
tabs.addTab(spec);
spec=tabs.newTabSpec("mitab2");
spec.setContent(R.id.tab2);
spec.setIndicator("TAB2",
res.getDrawable(android.R.drawable.ic_dialog_map)) ;
tabs.addTab(spec);
tabs.setCurrentTab(0);
tabs.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
Log.i("AndroidTabsDemo", "Pulsada pestaña: " + tabId);
}
});
}
}
Os dejo tambien el contenido del layout por si os sirve de algo:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TabHost android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent">
<LinearLayout android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/textView1"
android:text="Contenido Tab 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
¡</LinearLayout>
<LinearLayout android:id="@+id/tab2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="@+id/textView2"
android:text="Contenido Tab 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Gracias de antemano.
Un saludo. :cucu:
Tengo un problema y es que el metodo TabHost.setup() me detiene el programa cuando le toca ejecutar a la actividad a la que esta asociada, os dejo el código a ver si alguien puede echarme una manilla. :-)
public class Prueba extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fisicascnp);
Resources res = getResources();
TabHost tabs=(TabHost)findViewById(android.R.id.tabhost);.
tabs.setup(); //Aqui es donde salta la ejecución!!!!!!!!!
TabHost.TabSpec spec=tabs.newTabSpec("mitab1");
spec.setContent(R.id.tab1);
spec.setIndicator("TAB1",
res.getDrawable(android.R.drawable.ic_btn_speak_no w));
tabs.addTab(spec);
spec=tabs.newTabSpec("mitab2");
spec.setContent(R.id.tab2);
spec.setIndicator("TAB2",
res.getDrawable(android.R.drawable.ic_dialog_map)) ;
tabs.addTab(spec);
tabs.setCurrentTab(0);
tabs.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
Log.i("AndroidTabsDemo", "Pulsada pestaña: " + tabId);
}
});
}
}
Os dejo tambien el contenido del layout por si os sirve de algo:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TabHost android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent">
<LinearLayout android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/textView1"
android:text="Contenido Tab 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
¡</LinearLayout>
<LinearLayout android:id="@+id/tab2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="@+id/textView2"
android:text="Contenido Tab 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Gracias de antemano.
Un saludo. :cucu: