我的主Activity上有两个Buttons。当我启动该应用程序时,您可以单击一个Button,它将带您到右侧的Activity,但是我可以单击第二个Button一百次,但没有任何反应。它看起来就像第一个Button一样,当我按它时会变为通常的蓝色,但是如果我选择第一个button's Activity,然后返回到第一个Activity,第二个Button作品。我不明白这里发生了什么。

Main Activity :(请注意,SignUp是无效的按钮):

public class GameNetActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.first);
    getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

                Button SignIn = (Button) findViewById(R.id.button1);
    SignIn.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent myIntent = new Intent(view.getContext(), Welcome.class);
                    startActivityForResult(myIntent, 0);


            Button SignUp = (Button) findViewById(R.id.button2);
    SignUp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Signup.class);
            startActivityForResult(myIntent, 0);
                }

            });
        }
    });
  }
}

最佳答案

您已经在SignIn按钮的onClickListener中注册了onClickListener for SignUp按钮。取出并将其单独放在onCreate()中。

public void onCreate(Bundle savedInstanceState) {
...
....
    Button SignIn = (Button) findViewById(R.id.button1);
    SignIn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Welcome.class);
            startActivityForResult(myIntent, 0);
        }
    });


    Button SignUp = (Button) findViewById(R.id.button2);
    SignUp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Signup.class);
            startActivityForResult(myIntent, 0);
        }
    });
...
...}


希望这可以帮助!!

09-30 20:58