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 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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 :
1 |
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.
My name is Toto Sugito. This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.