第一项活动是用户保存其详细信息。单击保存按钮后,Alertdialog询问确定或取消。如果用户点击确定,则开始新活动。
protected final Dialog onCreateDialog(final int id) {
Dialog dialog = null;
switch(id) {
case DIALOG_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(AppointInformation.this);
builder.setMessage("Information saved successfully ! Add Another Info?")
.setCancelable(false)
.setPositiveButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(((Dialog)dialog).getContext(),CheckPatient.class));
}
})
.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
dialog = alert;
break;
default:
}
return dialog;
}
答案 0 :(得分:2)
我知道为时已晚但我想回答这个问题是为了帮助其他人,这对我有用:
Intent intent = new Intent(getContext(),OtherActivity.class);
context.startActivity(intent);
上下文是当前活动的背景。
答案 1 :(得分:1)
:
startActivity(new Intent(((Dialog)dialog).getContext(),CheckPatient.class));
到
startActivity(new Intent(getBaseContext(),CheckPatient.class));
或
startActivity(new Intent(Activityname.this,CheckPatient.class));
答案 2 :(得分:0)
在确定或取消按钮中单击,您可以写这个,
Intent intent = new Intent(this, NewActivity.class);
startActivity(intent);
答案 3 :(得分:0)
使用此代码
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(PresentActivity.this, NextActivity.class);
startActivity(intent);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.show();
答案 4 :(得分:0)
为此执行类似下面的操作。
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(AndroidAlertDialog.this); myAlertDialog.setTitle("--- Title ---");
myAlertDialog.setMessage("Alert Dialog Message");
myAlertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent(this, NextActivity.class);
startActivity(intent);
}});
myAlertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// do something when the Cancel button is clicked
}});
myAlertDialog.show();
答案 5 :(得分:0)
AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
alert.setTitle(title);
alert.setCancelable(false);
alert.setMessage(message);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
startActivity(new Intent(YourActivity.this, NewActivity.class));
}
});
alert.show();
使用上面的代码:::
答案 6 :(得分:-1)
这应该可以解决问题
Intent intent = new Intent(this, NewActivity.class);
startActivity(intent);