main.xml
--------
|button1| (button press)>page1.xml
|button2| (button press)>page2.xml
|button3| (button press)>page3.xml
|button4| (button press)>page4.xml
|button5| (button press)>page5.xml
|button6| (button press)>page6.xml
-------------------------------------------
When a button is clicked it goes to a corresponding page. What is the best/easiest way to implement this? I have tried everything to no avail when I try onclick listeners. I can get one listener to work but when I try to get more than one it messes up and I can't figure it out.
My current method is using these 2 java files
activity1.java
package install.fineline;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class Activity1 extends Activity {
Button Button1;
Button Button2;
Button Button3;
Button Button4;
Button Button5;
Button Button6;
public void addListenerOnButton() {
final Context context = this;
Button1 = (Button) findViewById(R.id.autobody);
Button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Activity2.class);
startActivity(intent);
}
});
Button2 = (Button) findViewById(R.id.glass);
Button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Activity2.class);
startActivity(intent);
}
});
Button3 = (Button) findViewById(R.id.wheels);
Button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Activity2.class);
startActivity(intent);
}
});
Button4 = (Button) findViewById(R.id.speedy);
Button4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Activity2.class);
startActivity(intent);
}
});
Button5 = (Button) findViewById(R.id.sevan);
Button5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Activity2.class);
startActivity(intent);
}
});
Button6 = (Button) findViewById(R.id.towing);
Button6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Activity2.class);
startActivity(intent);
}
});
}}
and here is my other java file
activity2.java
package install.fineline;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class Activity2 extends Activity {
Button button1;
public void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autobody);
}
Button button2;
public void onCreate2(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.glass);
}
Button button3;
public void onCreate3(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wheels);
}
Button button4;
public void onCreate4(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.speedy);
}
Button button5;
public void onCreate5(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sevan);
}
Button button6;
public void onCreate6(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.towing);
}}