我初學者到Android調用對話,而不是在每個活動重複編寫代碼的對話,我剛剛創建,其包含了所有的方法來顯示對話框一個班,我已經給了一小段代碼從另一個類
public class Dialogues extends Activity implements DialogueMethods {
public void showAlertDialog(Context context, String title, String message) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.show();
}
//this method am calling
public void showAlertDialog(Context context, String title, String message, String ButtonText, boolean cancel) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle(title);
alertDialog.setMessage(message);
if(cancel) {
alertDialog.setNegativeButton(ButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
finish();
}
});
}
alertDialog.show();
}
}
我打電話
//dialogObj is instance of the above class
dialogObj.showAlertDialog(MyActivity.this, "Error", "Not Connected to Internet", "Exit", true);
當我運行代碼對話框是可見的,但按鈕沒有,這是因爲DialogInterace.onClickListener的?我只是想知道這是好主意,做這樣的?如果是的話,那麼正確的做法是什麼。請幫幫我。
謝謝。
感謝您的清理。 – Manjunath
太棒了,高興地幫助你:) – Saveen