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?
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.
AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.
The way to make a checkbox list is to use setMultiChoiceItems . // setup the alert builder AlertDialog. Builder builder = new AlertDialog. Builder(context); builder.
setTitle(CharSequence title)AlertDialog alertDialog = alertDialogBuilder. create(); alertDialog. show(); This will create the alert dialog and will show it on the screen.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With