AlertDialog – MessageBox – Alert – Toast – Android sample

AlertDialog like MessageBox by WinApi:
If error: Unable to add window — token null is not for an application
try change get Context.

// you can put this text into some function body or case in switch statement
                new AlertDialog.Builder(this)
                    .setMessage("Hello boys!!!")
                    .setPositiveButton("OK", null)

Context context = getApplicationContext();
	AlertDialog.Builder builder = new AlertDialog.Builder(context);
	builder.setTitle("Select font size");
	final CharSequence[] chsSize= { "Small", "Medium", "Large"};
	builder.setSingleChoiceItems(chsSize, 0 /*sel.item*/, 
	new DialogInterface.OnClickListener() {
 	    public void onClick(DialogInterface dialog, int item) {
	    		 Toast.makeText(context, "Hello from dialog!!!", Toast.LENGTH_SHORT).show();
	AlertDialog alert = builder.create();;
This entry was posted in Android Examples Code and tagged , , . Bookmark the permalink.

Comments are closed.