Skip to content Skip to sidebar Skip to footer

Adding Custom Listview To Alert Dialog

I want to add custom list view too a alert dialog it works fine when i select a item from list and click the (setPositiveButton) the dialog close and the text is changed successful

Solution 1:

Please try these for setting list view inside alert dialog

AlertDialog.Builderalertdialog=newAlertDialog.Builder(context);
 LayoutInflaterinflaterr= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View  viewtemplelayout= inflaterr.inflate(R.layout.product_popup, null);
    YourAdapter adap=newYourAdapter(R.layout.product_add_popup_adapter,context);
    list.setAdapter(adap);
     alertdialog.setView(viewtemplelayout);
     alertdialog.show()

i think it help full for you.

Solution 2:

You can try this

Create costom adapter by extending the class as ArrayAdapter(its in your case)

Override getView() function(also inflate the view).

After that you can directly set adapter by using

 builder.setAdapter(costomAdapter);

Post a Comment for "Adding Custom Listview To Alert Dialog"