还记得在单项选择中选择AlertDialog [英] Remember what was selected in single choice AlertDialog
本文介绍了还记得在单项选择中选择AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 AlertDialog
它显示一个数组到一个单一的选择的选择:
I have an AlertDialog
which displays an array into a single selected choice:
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();
}
我想要做的就是第一次加载它应该显示默认的。有一次,我选择一个选项,对话框关闭,我提出了相同的对话框再次就应该表现出previously选择的选择我做了,然后滚动到它。
What I want to do is the first time it loads it should display the default. Once I select a choice and the dialog closes and I bring up the same dialog again it should show the previously selected choice I made and scroll to it.
我如何做到的呢?
截至目前,我可以选择的位置,但接下来呢?
As of right now, I can get the selected position but what next?
推荐答案
您可以存储所选择的价值在你的活动的变量
或使用的共享preferences
You can store the chosen value in a variable of your Activity
or using SharedPreferences
这篇关于还记得在单项选择中选择AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文