我正在使用apidemos中的以下代码..
return new AlertDialog.Builder(AlertDialogSamples.this)
.setIcon(R.drawable.ic_popup_reminder)
.setTitle(R.string.alert_dialog_multi_choice)
.setMultiChoiceItems(R.array.select_dialog_items3,
new boolean[]{false, true, false, true, false, false, false},
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton,
boolean isChecked) {
/* User clicked on a check box do some stuff */
}
})
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Yes so do some stuff */
}
})
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked No so do some stuff */
}
})
.create();
Run Code Online (Sandbox Code Playgroud)
在/* User clicked Yes so do some stuff */
,我没有提供isChecked变量..但是,我在/* User clicked on a check box do some stuff */
部分给出了isChecked ..显然我不想在复选框点击时更新我的SharedPrefs,以防用户点击取消..
那么如何获取setPositiveButton
onClick 上的复选框和值?
谢谢.
使用AlertDialog类的getListView().并获取listView.即,当你最后调用.create()时,这将获取一个新的AlertDialog.
然后使用以下方法之一:
1. getCheckItemPositions:SparseBooleanArray
2. getCheckedItemIds:long[]
Run Code Online (Sandbox Code Playgroud)
我可以为您提供演示代码.给我10-15分钟.
byte[]
传递对in 的引用setMultiChoiceItems()
。
final boolean[] booleans = {false, true, false, true, false, false, false};
Run Code Online (Sandbox Code Playgroud)
booleans
然后检查inside的值setPositiveButton()
。
如果您需要传递此AlertDialog
信息,请扩展AlertDialog
并创建一个字段boolean
,如 1 中所述。
归档时间: |
|
查看次数: |
10170 次 |
最近记录: |