2011-06-21 13 views
11

मुझे सूची दृश्य और संदेश दोनों के साथ संवाद बनाने की आवश्यकता है, हालांकि http://code.google.com/p/android/issues/detail?id=10948 के अनुसार यह मानक AlertDialog के साथ संभव नहीं है। तो मैंने पाठ और सूचीदृश्य के साथ कस्टम दृश्य बनाने का निर्णय लिया है, और इसे संवाद में संलग्न किया है।सूची दृश्य और संदेश के साथ संवाद

हालांकि, मेरी सूची दृश्य खाली खींचा गया है।

AlertDialog.Builder builder = new AlertDialog.Builder(this); 

    builder.setTitle("Hello, title!"); 

    LayoutInflater factory = LayoutInflater.from(this); 
    View content = factory.inflate(R.layout.dialog, null); 

    ListView lv = (ListView) content.findViewById(R.id.list); 
    lv.setAdapter(new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_single_choice, ITEMS)); 
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

    builder.setView(content).setPositiveButton("OK", this).setNegativeButton("Cancel", this); 

    AlertDialog alert = builder.create(); 
    alert.show(); 

इसके अलावा मेरे पास है: dialog_with_empty_list_view

किसी भी मदद की बहुत सराहना की है:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello, text!" /> 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/list" 
    ></ListView> 

</LinearLayout> 

यहाँ परिणाम है:

final String[] ITEMS = new String[] { "a", "b", "c" }; 

और यहाँ संवाद लेआउट है यहाँ जावा कोड है । धन्यवाद!

उत्तर

4

आप लाइनरलेआउट में android:orientation="vertical" गुम हैं।

आपका एक्सएमएल

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello, text!" /> 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/list" 

    ></ListView> 

</LinearLayout> 
1

सेट उन्मुखीकरण खड़ी की तरह अपने लेआउट में होगा

 <?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello, text!" /> 

    <ListView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/list" 
    ></ListView> 

    </LinearLayout> 

है

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