出于某种原因,无论我更改什么,我都无法摆脱ListView
. 您可以在“第 3 项”下看到它。
即使我有一个很长的列表,即使我一路下拉,也会发生这种情况。
我在布局中尝试了match_parent
和wrap_content
的所有组合,但没有成功。这是我的 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
这是我的AlertDialog
:
private void openMultiItemAlertDialog() {
ArrayList<String> selectedItems = new ArrayList<String>();
ArrayList<CharSequence> itemsList = new ArrayList<CharSequence>();
itemsList.add("item 1");
itemsList.add("item 2");
itemsList.add("item 3");
itemsList.add("item 4");
itemsList.add("item 5");
itemsList.add("item 6");
itemsList.add("item 7");
itemsList.add("item 8");
itemsList.add("item 9");
final CharSequence[] finalItemsList = itemsList.toArray(
new CharSequence[itemsList.size()]);
boolean[] booleanPrimativeArray = new boolean[finalItemsList.length];
checkedItems = new boolean[finalItemsList.length];
selectedItems.clear();
final View view = inflater.inflate(R.layout.dialog_list, null);
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.dialog_title)
.setView(view)
.setCancelable(true)
.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
dialogMultiItem = null;
}
})
.setMultiChoiceItems(finalItemsList, booleanPrimativeArray, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
checkedItems[which] = isChecked;
}
})
.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int i = 0; i < checkedItems.length; i++) {
if (checkedItems[i]) {
selectedItems.add((String) finalItemsList[i]);
}
}
doStuffWithSelectedItems(selectedItems);
dialog.dismiss();
dialogMultiItem = null;
}
});
dialogMultiItem = dialog.show();
}