gpt4 book ai didi

Android 按钮不起作用;其他按钮确实有效

转载 作者:行者123 更新时间:2023-11-30 04:22:24 24 4
gpt4 key购买 nike

我有一个包含两个按钮的应用程序,这两个按钮都应该将用户带到同一页面。这是他们的 .java 文件:

public class PageTwoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page2);

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


Button home2 = (Button) findViewById(R.id.ButtonHome2);
home2.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent myIntent2 = new Intent(view.getContext(), GuideApplicationActivity.class);
startActivityForResult(myIntent2, 0);
}



});}





});};};

有什么帮助吗?如果您需要查看任何其他文件,请询问。提前致谢,

最佳答案

您的开始和结束标签有问题。试试这个:

public class MainMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page2);

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

Button home2 = (Button) findViewById(R.id.ButtonHome2);
home2.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent myIntent2 = new Intent(view.getContext(), GuideApplicationActivity.class);
startActivityForResult(myIntent2, 0);
}
});
}
}

关于Android 按钮不起作用;其他按钮确实有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9070782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com