When trying to open another activity
the App stops, I have a activity
with a TabsHost
and I try to open another one with a TabHost
. I leave the code, I hope you can help me:
The java of MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabs= (TabHost) findViewById(R.id.Tabs2);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("Login");
spec.setIndicator("Login");
spec.setContent(R.id.Login);
tabs.addTab(spec);
spec=tabs.newTabSpec("registro");
spec.setIndicator("Registrase");
spec.setContent(R.id.Registrase);
tabs.addTab(spec);
tabs.setCurrentTab(0);
}
public void evtLogIn(View view) {
Intent intent = new Intent(this, MainPage.class);
startActivity(intent);
finish();
}
XML
of Main
:
<TabHost
android:id="@+id/Tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/Login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<EditText
android:layout_width="250dp"
android:hint="Nombre de usuario"
android:layout_height="wrap_content" />
<EditText
android:layout_width="250dp"
android:hint="Contraseña"
android:layout_height="wrap_content" />
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Ingresar"
android:onClick="evtLogIn"/>
</LinearLayout>
<LinearLayout
android:id="@+id/Registrase"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<EditText
android:layout_width="250dp"
android:hint="Nombre de usuario"
android:layout_height="wrap_content" />
<EditText
android:layout_width="250dp"
android:hint="Contraseña"
android:layout_height="wrap_content" />
<EditText
android:layout_width="250dp"
android:hint="Confirmar contraseña"
android:layout_height="wrap_content" />
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Registrarse"
/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
the other XML
is practically the same and the java of that Activity
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
TabHost tabs= (TabHost) findViewById(R.id.Tabs);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("Publicaciones");
spec.setIndicator("Publicaciones");
spec.setContent(R.id.Publicaciones);
tabs.addTab(spec);
spec=tabs.newTabSpec("Publica");
spec.setIndicator("Publica");
spec.setContent(R.id.Publicar);
tabs.addTab(spec);
tabs.setCurrentTab(0);
}