我有一个AlertDialog将数组显示为单个选择的选项:
AlertDialog
protected boolean blFrom, blTo; protected void showSelectToDialog() { boolean[] checkedDate = new boolean[toDate.length]; int count = toDate.length; DialogInterface.OnClickListener setD2 = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //TODO Auto-generated method stub onChangeSelectedTo(which); } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Select To Year"); builder.setSingleChoiceItems(toDate, count, setD2); builder.setCancelable(true); builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); dialog2 = builder.create(); dialog2.show(); } protected void onChangeSelectedTo(int j) { bTo.setText(toDate[j]); sTo = ((AlertDialog)dialog2).getListView().getCheckedItemPosition(); blTo = true; displayToast(String.valueOf(sTo)); to = j; dialog.dismiss(); }
我想做的是它第一次加载时应显示默认值。选择一个选项并关闭对话框后,我再次弹出相同的对话框,它应显示我先前做出的选择并滚动到该对话框。
我该如何完成?
截至目前,我可以获取所选职位,但是接下来该怎么办?
您可以将所选值存储在您的变量中,也可以Activity使用SharedPreferences
Activity