警报对话框中的多项选择
我正在关注以下问题。 我有一个带有 setMultipleChoiceItems 的警报对话框,已创建对话框 并正确显示,但是当我尝试取消选中任何选定的 项目,该项目保持选中状态。 以下是代码片段:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(context,
android.R.id.text1,
c,
new String[] {label},
new int[] {android.R.id.text1}
);
AlertDialog dialog=new AlertDialog.Builder(context)
.setTitle(title)
.setPositiveButton(R.string.okBtn, null)
.setNegativeButton(R.string.cancelBtn, null)
.setMultiChoiceItems(c,state,label,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
Log.v("TEST", "onClick(..) called with value " + which +
" / "+ isChecked);
}
})
.create();
dialog.show()
尽管如此,方法 OnMultiChoiceClickListener() 被调用并在日志 I 中 可以看到: “onClick(..) 调用值为 2 / false” 所以它说所选项目应该是FALSE(未选中)但是 对话框不会更新并且项目保持选中状态。 有什么想法为什么会这样吗?
I'm focusing following problem.
I have an alert dialog with setMultipleChoiceItems, dialog is created
and shown correctly but when I try to uncheck any of the selected
items, the item stays checked.
Here is the snippet of the code:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(context,
android.R.id.text1,
c,
new String[] {label},
new int[] {android.R.id.text1}
);
AlertDialog dialog=new AlertDialog.Builder(context)
.setTitle(title)
.setPositiveButton(R.string.okBtn, null)
.setNegativeButton(R.string.cancelBtn, null)
.setMultiChoiceItems(c,state,label,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
Log.v("TEST", "onClick(..) called with value " + which +
" / "+ isChecked);
}
})
.create();
dialog.show()
Althought, method OnMultiChoiceClickListener() is called and in log I
can see:
"onClick(..) called with value 2 / false"
so it says that chosen item is supposed to be FALSE (unchecked) but
the dialog is not updated and item stays checked.
Any ideas why it is like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此:http://code.google.com/p/android /issues/detail?id=2998
至少据我了解,当选中/取消选中该项目时,您必须更新数据库。就我个人而言,我不喜欢这个想法,对于多项选择列表,我使用 ListArrays 而不是游标:
这不是最好的方法,但我不知道更好的方法。
Because of this: http://code.google.com/p/android/issues/detail?id=2998
At least as far as I understand it, you have to update you database when the item is checked/unchecked. Personally, I don't like this idea and for multiple choice lists I use ListArrays instead of cursors:
It is not the best way to do it, but I don't know any better.