我已经看过很多关于如何更改 android 屏幕的教程,但我无法理解/制作所有这些教程,有人可以帮助我完成我的项目。我有四个 xml 文件,它们都有三个按钮,但只有两个用于设置页面。我可以让应用程序加载任何其他页面(但不能建立按钮)(重要的一点)。任何帮助表示赞赏。
package com.store.shrek2;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
int activityloaded = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button) this.findViewById(R.id.button1);
Button button2 = (Button) this.findViewById(R.id.button2);
Button button3 = (Button) this.findViewById(R.id.button3);
Button button4 = (Button) this.findViewById(R.id.button4);
Button button5 = (Button) this.findViewById(R.id.button5);
Button button6 = (Button) this.findViewById(R.id.button6);
if(activityloaded == 1){
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}});
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
activityloaded = 2;
}});
button3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
activityloaded = 4;
setContentView(R.layout.activity4);
}});
}
if(activityloaded == 2){
setContentView(R.layout.activity2);
button4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.activity3);
}});
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.store.shrek2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity2"></activity>
<activity android:name=".activity3"></activity>
<activity android:name=".activity4"></activity>
</application>
</manifest>