I am trying to make an app that has multiple layouts. Is there a certain efficient way to display multiple layouts? My app has buttons and each button leads to a different layout. Therefore, can anyone give me ideas on what to use? I am a 14 year old and i am completely new to android. I have a moderate amount of background in java, that's all. Thanks for any help! Here is my main activity...
package com.example.submenus;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
public void onBackPressed() {
setContentView(R.layout.activity_main);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// This is for Audi A4
Button button = (Button) findViewById(R.id.a4button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.audi);
}
} );
// This is for Audi A6
Button button1 = (Button) findViewById(R.id.a6button);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.audia6);
}
} );
// This is for Audi Q5
Button button2 = (Button) findViewById(R.id.q5button);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.audiq5);
}
} );
// This is for Audi R8
Button button3 = (Button) findViewById(R.id.r8button);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.audir8);
}
} );
}
}
Again, just want to say this is an app that has a main menu. In that menu i have multiple buttons that lead to a different layout correspondingly. The app works fine until i hit the back button then click a button. Let me rephrase that... I click on a button and it takes me to the correct layout. I then can hit the back button and it brings the layout back to the main menu just like it should. Then if i click another button the app freezes and crashes. Is there a way to fix this? Thanks for any help!