Potrzebuję utworzyć okno dialogowe z listView i wiadomości, jednak zgodnie z http://code.google.com/p/android/issues/detail?id=10948 nie jest to możliwe przy standardowym AlertDialog. Dlatego zdecydowałem się stworzyć niestandardowy widok z tekstem i listview i dołączyć go do okna dialogowego.Okno dialogowe z widokiem listy i wiadomością
Jednak widok mojej listy jest pusty. Oto kod 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();
Również mam:
final String[] ITEMS = new String[] { "a", "b", "c" };
i tutaj jest układ dialogowe:
<?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>
Oto wynik:
Każda pomoc jest mile widziana . Dzięki!