2016-03-23 83 views

回答

1
public void openDialog(View view){ 
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 
    alertDialogBuilder.setMessage("Are you sure,You wanted to make decision"); 

    alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() { 
    @Override 
    public void onClick(DialogInterface arg0, int arg1) { 
     Toast.makeText(MainActivity.this,"You clicked yes button",Toast.LENGTH_LONG).show(); 
    } 
    }); 

    alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() { 
    @Override 
    public void onClick(DialogInterface dialog, int which) { 
     finish(); 
    } 
    }); 

    AlertDialog alertDialog = alertDialogBuilder.create(); 
    alertDialog.show(); 

}

只需調用此方法openDialog();在你的setContentView(R.layout.activity_main)之後; 示例

setContentView(R.layout.activity_main); 
openDialog(); 
+0

它工作的非常好! –

+0

但是,不是肯定而是否,我喜歡它只有一個選項,如解僱,我怎麼能這樣做 –

+0

只是使用Poisitive按鈕。刪除負面的按鈕代碼。它會顯示單個按鈕。並隨意製作文字 – Ameer