gpt4 book ai didi

android - 警报对话框 + Intent

转载 作者:行者123 更新时间:2023-11-29 17:39:44 24 4
gpt4 key购买 nike

public void screen2 (View view) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("screen2");
builder.setMessage("go to screen2?");

builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(this,Screen2Activity.class);
startActivity(intent);
}
}
}

我想从 AlertDialog 启动一个 Activity ,但我在 Intent intent = new Intent(this,Tela2Activity.class);

上发现了一个错误

screen2 链接到按钮的“onclick”

最佳答案

修改这部分代码:

Intent intent = new Intent(this,Screen2Activity.class);
startActivity(intent);

对此:

Intent intent = new Intent(FirstActivity.this,Screen2Activity.class);
startActivity(intent);

完整代码:

public void screen2 (View view) {

final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("screen2");
builder.setMessage("go to screen2?");

builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(FirstActivity.this,Screen2Activity.class);
startActivity(intent);

}

关于android - 警报对话框 + Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29147532/

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