final EditText show_brand_list = (EditText) findViewById(R.id.brand);
show_brand_list.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String checkedname = show_brand_list.getText().toString();
for (int i = 0; i < listItemsx.length; i++) {
if (checkedname.contains(listItemsx[i])) {
checkedItemsx[i] = true;
} else {
checkedItemsx[i] = false;
}
}
AlertDialog.Builder mBuilder = new AlertDialog.Builder(activity_competitor_edit.this, R.style.MyDialogTheme);
mBuilder.setTitle("List of Brands:(" + valuext + ")");
mBuilder.setMultiChoiceItems(listItemsx, checkedItemsx, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
try {
if (isChecked) {
mUserItemsx.add(which);
} else {
mUserItemsx.remove((Integer) which);
}
} catch (Exception e) {
}
}
});
mBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mUserItemsx.size() != 0) {
show_brand_list.setText("");
String itemx = "";
for (int i = 0; i < mUserItemsx.size(); i++) {
itemx = itemx + listItemsx[mUserItemsx.get(i)];
if (i != mUserItemsx.size() - 1) {
itemx = itemx + ",";
}
}
show_brand_list.setText(itemx);
} else {
show_brand_list.setText("");
}
}
});
// mBuilder.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// dialog.dismiss();
// }
// });
mBuilder.setNeutralButton("Clear All", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int i = 0; i < checkedItemsx.length; i++) {
checkedItemsx[i] = false;
mUserItemsx.clear();
String item = "";
setcompother(item);
show_brand_list.setText("");
}
}
});
mBuilder.create().show();
}
});
这就是我的代码所要做的。当我单击EditText时,setMultiChoiceItems警报对话框将显示基于我的EditText包含内容的选中显示的项目。但是,当我取消选中一个数据时。我EditText中的所有数据都消失了,而不是被取消选中的项目。我的代码有什么问题。我不是因为数组还是在“确定”按钮中