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开始活动,但我在Intent intent = new Intent(this,Tela2Activity.class);
screen2链接到' onclick'一个按钮
答案 0 :(得分:3)
更改此部分代码:
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);
}