在VB中使用你寫一個提示框:VB MSGBOX到Java警報
Response=Msgbox("Click YES to continue, NO to Abort",vbyesno)
If response=vbyes...do something
在Java中,我們必須寫碼更多的代碼來做到這一點。我想寫的是一個效用函數,可以從任何地方調用並返回響應。 我寫道:
protected static boolean Response=false;
public boolean CreateAlert(String AlertMessage){
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage(AlertMessage);
alertbox.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Response=true;
}
});
alertbox.setNegativeButton("NO" , new DialogInterface.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
Response=false;
}
});
alertbox.show();
return Response;
但是,我不能,因爲AlertDialogBuilder需要這這大概意味着我需要從另一個類傳遞一個上下文變量移動到不同的班級。 一個消息框的互動形式幾乎是必不可少的組成部分,和所有我想要的是加1行代碼每個我打開一個消息框時間......一定有辦法!