Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

menu alert dialog in android

//create an instance of AlertDialog.Builder
AlertDialog.Builder builder = new AlertDialog.Builder(this);

//get string array (languages)
final String[] language = getResources().getStringArray(R.array.languages);

builder.setTitle(getText(R.string.select_language_title))

        //Set language(list of languages) to be displayed in the dialog as the content.
        .setItems(language, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int indexPosition) {

                // The 'indexPosition' argument contains the index position
                // of the selected item
                String selectedItem = Arrays.asList(language).get(indexPosition);
                Toast.makeText(getApplicationContext(), "Selected Language: " + selectedItem, Toast.LENGTH_LONG).show();

            }
        });

//create an AlertDialog
AlertDialog alertDialog = builder.create();

//display the dialog on screen
alertDialog.show();
Source by c1ctech.com #
 
PREVIOUS NEXT
Tagged: #menu #alert #dialog #android
ADD COMMENT
Topic
Name
9+7 =