April 28, 2016
Android show alert window with button
I am learn about android programming in my free time. I am planned to create a simple alert window with a button. We can use AlertDialog class to create android alert window in Android. The sample output using this class as like picture below.
I have created a simple function how to create Android alert window using AlertDialog class. Please check this subroutine :
private void showAlertOk(String strtitle, String strtext, String strbutton) { AlertDialog.Builder builder = new AlertDialog.Builder(formQuestions.this); builder.setTitle(strtitle); builder.setMessage(strtext); builder.setPositiveButton(strbutton, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //add our code in here } }); builder.show(); }
We can give parameter to this Android alert window subroutine to give same result like picture above using command :
showAlertOk("Information", "Please select the right answer", "Close")
I hope this simple subroutine can give you more explaining about how to create alert window in Android.