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
-------------------------------------------
當單擊按鈕時,它會轉到相應的頁面。什麼是最好/最簡單的方法來實現這一點?當我嘗試onclick聽衆時,我試過一切都無濟於事。我可以讓一個聽衆工作,但當我試圖獲得一個以上的聽衆時,它會混亂起來,我無法弄清楚。 我當前方法是使用這些2個java文件
activity1.java帶onclick聽衆的Android按鈕導航
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 =(按鈕)findViewById(R.id.towing);
Button6.setOnClickListener(新OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Activity2.class);
startActivity(intent);
}
});
}}
,這裏是我的其他Java文件
activity2.java
包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);
}}
,只是不喜歡這個工作。你必須回到android hello世界並從那裏前進。 android不知道你的onCreate1,2,3。它只知道onCreate。你會做什麼是完全使用不同的活動。 – njzk2