Android Radio Buttons及其状态变化

时间:2013-04-26 05:11:08

标签: android android-alertdialog android-checkbox

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

enter image description here

我的代码:

   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;

0 个答案:

没有答案