Tela 1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="br.com.android.Layouts" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tela Principal" />
<Button
android:id="@+id/bttela2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Tela2" />
</LinearLayout>
Tela 2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="br.com.android.Layouts" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tela 2" />
<Button
android:id="@+id/bttelainicial"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Tela Inicial" />
</LinearLayout>
package br.com.android;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class Layouts extends ActionBarActivity {
public void carregaTelaPrincipal (){
setContentView(R.layout.activity_layouts);
Button bttela2 = (Button) findViewById(R.id.bttela2);
bttela2.setOnClickListener (new View.OnClickListener() {
public void onClick(View v) {
CarregaTela2();
}
});
}
public void CarregaTela2(){
setContentView (R.layout.tela2);
Button bttelainicial = (Button)
findViewById (R.id.bttelainicial);
bttelainicial.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
carregaTelaPrincipal();
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layouts);
carregaTelaPrincipal();
}
}
0 comentários:
Postar um comentário