Android Intent in Dialog box

夙愿已清 提交于 2019-12-11 19:45:21

问题


I'm new android developer so I need your help. I'm making a app in which a button action open a dialog box. Dialog box has a button. Can i intent on the button action? Kindly give some good possible ways. Thanks


回答1:


you want to handle the "Ok" event and perform some action.

You have a method to handle the dialog.

public void displayAlertToChangeActivity(){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("title");
alert.setMessage("massage");

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
   //Do something here where "ok" clicked and then perform intent from activity context
   Intent intent = new Intent(MyActivity.this, MyNextActivity.class);
   MyActivity.this.startActivity(intent);

}
});

alert.show();

}



来源:https://stackoverflow.com/questions/22645107/android-intent-in-dialog-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!