Tôi cần tạo hộp thoại có cả ListView và tin nhắn, tuy nhiên theo http://code.google.com/p/android/issues/detail?id=10948 thì không thể với AlertDialog chuẩn. Vì vậy, tôi đã quyết định tạo chế độ xem tùy chỉnh với văn bản và danh sách xem và đính kèm nó vào hộp thoại.Hộp thoại với chế độ xem danh sách và thông báo
Tuy nhiên, chế độ xem danh sách của tôi bị trống. Đây là mã 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();
Ngoài ra tôi có:
final String[] ITEMS = new String[] { "a", "b", "c" };
và đây là cách bố trí thoại:
<?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>
Dưới đây là kết quả:
Any help is appreciated rất nhiều . Cảm ơn!