由於某種原因,無論我改變什麼,我都無法擺脫我的ListView
中最後一項之後的額外空間。您可以在「項目3」下看到它。使用MultiChoiceItems的AlertDialog中的listview中的額外空間
發生這種情況,即使我有一個長長的名單,即使我拉一路下跌。
我試着在我的佈局,但沒有成功的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();
}
你設置高度爲「wrap_content」嘗試設置爲「fill_parent」 btw你在哪裏聲明你的按鈕在xml? – r4jiv007
這是什麼.setView(view)在那裏做? – rhoadster91
@ r4jiv007我試過了每個可能的「wrap_content」和「match_parent」的組合。儘管如此,這是一個很好的補充。我已經更新了這個問題。而不是迂腐,但它是API級別8的「match_parent」:)至於按鈕,我沒有用XML聲明它們。它們在AlertDialog構建器中設置。 – Patrick