帮助......我有一个问题......这是鳕鱼......
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case IDD_COLOR:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
ListView listView = new ListView (this);
builder.setInverseBackgroundForced(true);
listView.setAdapter(new ArrayAdapter(this, android.R.layout.select_dialog_multichoice, mColors ));
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
switch (arg2) {
case 0:
if (!((CheckedTextView)arg0.getChildAt(arg2)).isChecked())
{
((CheckedTextView)arg0.getChildAt(arg2)).setChecked(true);
} else
((CheckedTextView)arg0.getChildAt(arg2)).setChecked(false);
break;
case 1:
if (!((CheckedTextView)arg0.getChildAt(arg2)).isChecked())
{
((CheckedTextView)arg0.getChildAt(arg2)).setChecked(true);
} else
((CheckedTextView)arg0.getChildAt(arg2)).setChecked(false);
break;
case 2:
if (!((CheckedTextView)arg0.getChildAt(arg2)).isChecked())
{
((CheckedTextView)arg0.getChildAt(arg2)).setChecked(true);
} else
((CheckedTextView)arg0.getChildAt(arg2)).setChecked(false);
break;
}
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setView(listView);
return builder.create();
default:
return null;
}
如何通过按取消按钮取消点击的内容?因为它一直保存所点击的内容。
答案 0 :(得分:0)
尊利,
这适用于您的情况吗?
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
((CheckedTextView)arg0.getChildAt(arg2)).setChecked(false)
dialog.cancel();
}
});
我还没有对它进行过测试,但是如果您在调用dialog.cancel();
之前只是取消选中该框,则无法进行检查。