I am new to android, instead of writing code repeatedly for dialogue in each action, I just created one class that contains all the methods for displaying the dialogue, I gave a small piece of code
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();
}
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();
}
}
Called
//dialogObj is instance of the above class
dialogObj.showAlertDialog(MyActivity.this, "Error", "Not Connected to Internet", "Exit", true);
When I launch the code dialog, apparently, but the button is not specified, is it because of DialogInterace.onClickListener ?, I just want to know, is this a good idea how to do this ?, if that is the right way to do it. please help me.
thank.
source
share