我初学者到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