Open MyActivity.java and replace the contents of the onCreate method with the following:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(items, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
return;
}
});
builder.create().show();
}
Once you redeploy (mvn clean install) and launch your app, you will see the dialog. Choose one and see the popup.
thanks
ReplyDeleteno problem. glad it helped!
ReplyDeleteIts nice example. Keep it up
ReplyDeletethanks :D
ReplyDelete