还记得在单项选择中选择AlertDialog单项、AlertDialog

由网友(微笑、只是一个弧度而已)分享简介:我有一个 AlertDialog 它显示一个数组到一个单一的选择的选择:I have an AlertDialog which displays an array into a single selected choice:protected boolean blFrom, blTo;protected void...

我有一个 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

阅读全文

相关推荐

最新文章