所以,我有三個活動/屏幕。在第一個屏幕上,有一個按鈕,當按下時,打開第二個屏幕。在第二個屏幕上,有一個按鈕可以打開屏幕3,但另一個按鈕可以返回屏幕1.我無法在屏幕2上同時使用這兩個按鈕。 (一個工作,另一個不工作,反之亦然)。用於打開新活動的按鈕?
屏幕1級的Java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class FirstActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.part1to2);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Screen2.class);
startActivityForResult(myIntent, 0);
}
});
}
}
屏幕2.java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Screen2 extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Button next = (Button) findViewById(R.id.goto1);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
Button next = (Button) findViewById(R.id.goto3);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Screen3.class);
startActivityForResult(myIntent, 0);
finish();
}
});
}
});
}
}
屏幕3.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Screen3 extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
}
}
我的清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gamer.network2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".FirstActivity"
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=".Screen2"></activity>
<activity android:name=".Screen3"></activity>
</application>
</manifest>
那麼,如何讓屏幕2上的兩個按鈕同時工作?
你怎麼有兩個名稱相同的按鈕?這是複製/粘貼錯誤嗎? – Egor
嗯,我猜我想我可以從按鈕的代碼工作,並複製它,所以另一個按鈕將工作,但我想我忘了改變這一點。所以我現在改了它,但它仍然不起作用。 – Cole