2015-11-03 10 views
8

पर विभाजक प्रदर्शित नहीं करता है मैं इस वर्ग है:AlertDialog एक सूची

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(); 


} 

सूचना संवाद के बाद खोला जाता है आह्वान openDialog(), लेकिन बात यह है कि यह आइटम के बीच विभाजक का प्रदर्शन नहीं करता है। मैं इस प्राप्त करना चाहते हैं:
http://2.bp.blogspot.com/-i00d8VG6WsQ/UrGIeyb-8II/AAAAAAAAHwA/8MPWP5qrQ78/s500/alertdialog-with-simple-listview.png

और, वास्तव में, मैं समझ गया लेकिन ग्रे विभाजक के बिना।
क्यों कोई विचार?

enter image description here

उत्तर

26

बदलें AlertDialog सूची आइटम विभाजक रंग के रूप में:

AlertDialog alertDialogObject = dialogBuilder.create(); 
ListView listView=alertDialogObject.getListView(); 
listView.setDivider(new ColorDrawable(Color.BLUE)); // set color 
listView.setDividerHeight(2); // set height 
alertDialogObject.show(); 
+0

धन्यवाद लेकिन मैं .getListView() – JoCuTo

+2

तक पहुंच नहीं कर सकता। यह काम करता है! लेकिन आपको 'संवाद चेतावनी DialogObject = dialogBuilder.create(); 'alertDialog alertDialogObject = dialogBuilder.create(); ' –

+0

हाँ काम करता है! बहुत बहुत धन्यवाद – JoCuTo

0

यह है क्योंकि आप Android पर अपने एप्लिकेशन 5.0+ जो सामग्री डिजाइन द्वारा चलाए जा रहे शायद है।

"पुराने" देखो के लिए, बस Holo शैली के साथ अपने संवाद का निर्माण:

ContextThemeWrapper themedContext = new ContextThemeWrapper(getContext(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar); 
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); 
// ... then create your dialog 

हालांकि यह कुछ उपयोगकर्ताओं को (विशेष रूप से लॉलीपॉप और Marshmallow पर के लिए अजीब लग सकता है, तो मैं कस्टम का उपयोग करते हुए देखने की सलाह देते आपके संवाद के लिए विचार।

+0

धन्यवाद डैनियल, अच्छा बिंदु लेकिन काम नहीं करता है, अभी भी विभाजक :( – JoCuTo

+0

बिना आप शायद अपने वर्तमान प्रगति के बारे में एक स्क्रीनशॉट जोड़ सकते हैं? –

+0

स्क्रीनशॉट जोड़ा – JoCuTo

संबंधित मुद्दे