Search This Blog

23 April 2010

List picker and fading popup notice

This example can be created from any of the previous as we are just going to replace the content of MyActivity.  In this case, we are going to create a popup, allow the user to choose one, and then show a temporary message telling them what they chose.  This example is directly from the developer documentation.

Open and replace the contents of the onCreate method with the following:

    public void onCreate(Bundle savedInstanceState) {

        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();

Once you redeploy (mvn clean install) and launch your app, you will see the dialog.  Choose one and see the popup.