0
multiChoiceItemsを使用してArrayListを表示するダイアログを使用しようとしています。削除したいアイテムを確認したいのですが、削除するボタンをクリックしてダイアログを閉じ、次にダイアログを開くときにアイテムを削除させたいと思います。multiChoiceItemsダイアログから項目を削除するインターフェイスが動作しない
以下のコードをデバッグすると、選択されたすべてのアイテムについてループが行われますが、実際に削除されるアイテムはありません。私はおそらくここではかなり些細なものが欠けているように感じ、私はいくつかの助けが大好きです!
複数のアイテムを削除した場合、インデックスを変更する必要があるので、心配しないでください。私は最初のアイテムを単独で取り除くことができたらそれをやります!
ありがとうございます!
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Title");
mSelectedItems.clear();
builder.setMultiChoiceItems(myList,null,
new DialogInterface.OnMultiChoiceClickListener(){
@Override
public void onClick(DialogInterface dialog,int which, boolean isChecked){
if (isChecked) {
// If the user checked the item, add it to the selected items
mSelectedItems.add(which);
} else if (mSelectedItems.contains(which)) {
// Else, if the item is already in the array, remove it
mSelectedItems.remove(Integer.valueOf(which));
}
}
});
builder.setPositiveButton("Remove from list", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for(int i=0;i<mSelectedItems.size();i++){
arrayChoices.remove(mSelectedItems.get(i));
}
myList = arrayChoices.toArray(new CharSequence[arrayChoices.size()]);
}
});
builder.setNegativeButton("End", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
インデックスを直接指定するとアイテムを削除できます。例:arrayChoices.remove(0)。だから私は整数として私の削除引数を認識していないかもしれないと思うが、私はなぜそれがしないのか分からない。誰か説明がありますか? – lhbortho