我正在尝试制作Android应用,我想让用户选择工作日。 现在我有了AlertDialog设置,用户可以选择几个选项。 但是当用户点击“确定”按钮时,我无法弄清楚如何保存选择。
代码:
new AlertDialog.Builder(this)
.setTitle("Weekdays")
.setMultiChoiceItems(weekdayOptions, selections, new DialogInterface.OnMultiChoiceClickListener()
{
public void onClick(DialogInterface dialog, int whichButton, boolean isChecked)
{
if( selections[whichButton] == true)
{
//Only need the selected(True) values
Log.d(TAG, "Choice: " + whichButton);
}
Log.d(TAG, "Weekdays Selected: " + whichButton + selections[whichButton]);
selections[whichButton] = isChecked;
}
})
.setPositiveButton("OK", new DialogButtonClickHandler())
.create()
.show();
}
public class DialogButtonClickHandler implements DialogInterface.OnClickListener
{
public void onClick( DialogInterface dialog, int clicked )
{
switch(clicked)
{
case DialogInterface.BUTTON_POSITIVE:
//I want to check here what the user selected
break;
}
}
}
因此,当用户点击BUTTON_POSITIVE时,我想保存whichButton和选择[whichButton],我认为是二维数组。