Подтвердить что ты не робот

Диалог со списком и сообщением

Мне нужно создать диалог как с ListView, так и с сообщением, однако, согласно http://code.google.com/p/android/issues/detail?id=10948, это невозможно при использовании стандартного AlertDialog. Поэтому я решил создать пользовательский вид с текстом и списком и прикрепить его к диалоговому окну.

Однако мой список списков пуст. Вот код Java:

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

Также у меня есть:

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

и вот диалоговое окно:

<?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>

Вот результат: dialog_with_empty_list_view

Любая помощь приветствуется. Спасибо!

4b9b3361

Ответ 1

Вам не хватает android:orientation="vertical" в linearlayout.

Ваш xml будет

<?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>

Ответ 2

заданная ориентация вертикальная, как

      <?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>

в вашем макете