How to show listview in Android alertdialog

To Show simple Listview in Alertdialog, just create List of strings & then pass it to alert dialog object.

Here is the sample example shows alertdialog with list of animals.

  public void ShowAlertDialogWithListview()  
   {  
        List<String> mAnimals = new ArrayList<String>();  
        mAnimals.add("Cat");  
        mAnimals.add("Dog");  
        mAnimals.add("Horse");  
        mAnimals.add("Elephant");  
        mAnimals.add("Rat");  
        mAnimals.add("Lion");  
        //Create sequence of items  
        final CharSequence[] Animals = mAnimals.toArray(new String[mAnimals.size()]);  
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);  
        dialogBuilder.setTitle("Animals");  
        dialogBuilder.setItems(Animals, new DialogInterface.OnClickListener() {  
        public void onClick(DialogInterface dialog, int item) {  
             String selectedText = Animals[item].toString();  //Selected item in listview
        }  
      });  
      //Create alert dialog object via builder  
      AlertDialog alertDialogObject = dialogBuilder.create();  
      //Show the dialog  
      alertDialogObject.show();  
   }  

Also onClick method is handled in the above example to read the selected item from Listview.