0

我用 3 个单选按钮创建了一个警报。在警报中我有确定和取消按钮,在确定中我放置了 3 个单选按钮功能。我正在发生的事情,第一个单选按钮在布局中设置为 true 但我想要,当我单击第二个单选按钮并按 OK 时,再次打开警报时,第二个单选按钮保持选中状态。但这并没有发生。当我再次单击警报对话框时,它会显示单击的第一个单选按钮。我见过很多例子,但没有结果。

在此处输入图像描述

我的代码:

   case SYNC_ALERT:
        AlertDialog.Builder alertbuilder = new AlertDialog.Builder(this);
        alertbuilder.setMessage("Synchronization");
        alertbuilder.setCancelable(false);
        LayoutInflater buildinflater = this.getLayoutInflater();
        View SyncView= buildinflater.inflate(R.layout.sync_layout, null);
        alertbuilder.setView(SyncView);
        defaultchkbox = (RadioButton)SyncView.findViewById(R.id.defaultchkbox);
        after15mint = (RadioButton)SyncView.findViewById(R.id.after15mint);
        afternmint = (RadioButton)SyncView.findViewById(R.id.afternmint);
        alarms = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        alertbuilder.setPositiveButton("OK", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which)
            {
                //Implement search method here
                if(defaultchkbox.isChecked())
                {
                    BroadCastReceiver bcr = new BroadCastReceiver();
                    bcr.CancelAlarm(getApplicationContext());
                    adapter.refresAdapter(data);
                    Treedata();

                }
                else if(after15mint.isChecked())
                { 
                    // Create alarm intent
                    defaultchkbox.setChecked(false);
                    Intent downloader = new Intent(getApplicationContext(), BroadCastReceiver.class);
                    PendingIntent recurringDownload = PendingIntent.getBroadcast(getApplicationContext(),
                            0, downloader, PendingIntent.FLAG_UPDATE_CURRENT);
                    alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
                            1000 * 10, recurringDownload);
                }
                else
                {
                    defaultchkbox.setChecked(false);
                    after15mint.setChecked(false);
                    BroadCastReceiver bcr = new BroadCastReceiver();
                    bcr.CancelAlarm(getApplicationContext());
                    showDialog(TIME_ALERT);
                }
              }
       });
        alertbuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which) 
            {
                dialog.dismiss();
            }
        });
            AlertDialog alertdialog = alertbuilder.create();
            alertdialog.show();
            break;
4

0 回答 0