Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog does not show dividers on a list

I have this class:

public class PageDetailInfoView extends FrameLayout {

//few constructors and methods

//method to show an AlertDialog with a list
private void openDialog(){

    List<String> mTags = new ArrayList<String>();
    mTags.add("Item1");
    mTags.add("Item2");
    mTags.add("Item3");
    mTags.add("Item4");
    mTags.add("Item5");
    mTags.add("Item6");

    final CharSequence[] tags = mTags.toArray(new String[mTags.size()]);
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle("Title");
    builder.setItems(tags, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
        //do something
        }
    });

    Dialog alertDialogObject = builder.create();
    alertDialogObject.show();


}

The Alert dialog is opened after invoke openDialog() but the thing is that it does not exhibit the dividers between items. I would like to get this:
http://2.bp.blogspot.com/-i00d8VG6WsQ/UrGIeyb-8II/AAAAAAAAHwA/8MPWP5qrQ78/s500/alertdialog-with-simple-listview.png

and ,in fact, I get it but without the Gray dividers.
Any idea about why?

enter image description here

like image 594
JoCuTo Avatar asked Nov 03 '15 13:11

JoCuTo


People also ask

How do I get view from AlertDialog?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken text view.

How many buttons can an AlertDialog display?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.

Which method is used to set the list in AlertDialog in Android?

The way to make a checkbox list is to use setMultiChoiceItems . // setup the alert builder AlertDialog. Builder builder = new AlertDialog. Builder(context); builder.

How do I use AlertDialog?

setTitle(CharSequence title)AlertDialog alertDialog = alertDialogBuilder. create(); alertDialog. show(); This will create the alert dialog and will show it on the screen.


1 Answers

Change AlertDialog List items divider color as:

AlertDialog alertDialogObject = dialogBuilder.create();
ListView listView=alertDialogObject.getListView();  
listView.setDivider(new ColorDrawable(Color.BLUE)); // set color
listView.setDividerHeight(2); // set height 
alertDialogObject.show();
like image 98
ρяσѕρєя K Avatar answered Oct 01 '22 02:10

ρяσѕρєя K