0

我在警报对话框中有单选按钮列表,我必须在 10 mints、15 mints 和 n mints 后选择诸如警报之类的选项,但是当我单击一个单选按钮并再次打开一个 laert 对话框单选按钮保持未单击但我想选择要单击的选项。怎么可能?是否需要将其状态存储在数据库或任何其他解决方案中?

我的活动:

 case RADIOBTN_DIALOG_ID:    
        AlertDialog.Builder builder2=new AlertDialog.Builder(Task_Details.this)
        .setTitle("Select Reminder Time")
        .setSingleChoiceItems(reminder_radio, -1, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            switch(which)
            {
            case 0:
                AlarmReceiver alarm = new AlarmReceiver();
                alarm.CancelAlarm(getApplicationContext());
                alarm.OneMintAlarm(getApplicationContext());
                Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
                break;
            case 1:
                AlarmReceiver alarm1 = new AlarmReceiver();
                alarm1.CancelAlarm(getApplicationContext());
                alarm1.TenMintAlarm(getApplicationContext());
                Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                AlarmReceiver alarm2 = new AlarmReceiver();
                alarm2.CancelAlarm(getApplicationContext());
                alarm2.FifteenMintAlarm(getApplicationContext());
                Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
                break;
            case 3:
                AlarmReceiver alarm3 = new AlarmReceiver();
                alarm3.CancelAlarm(getApplicationContext());
                alarm3.nMintAlarm(getApplicationContext());
                Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
                break;
            }
            dialog.dismiss();
        }
    });

广播接收器活动:

 public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, " Alarm Received !!! ", Toast.LENGTH_LONG).show();

}
public void CancelAlarm(Context context)
{
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(sender);
}
public void OneMintAlarm(Context context)
{
    AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent recurringDownload = PendingIntent.getBroadcast(context,
            0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
            1000 * 10, recurringDownload);
}
public void TenMintAlarm(Context context)
{
    AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent recurringDownload = PendingIntent.getBroadcast(context,
            0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
            1000 * 600, recurringDownload);
}
public void FifteenMintAlarm(Context context)
{
    AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent recurringDownload = PendingIntent.getBroadcast(context,
            0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
            1000 * 900, recurringDownload);
}

public void nMintAlarm(Context context)
{
    }

请建议怎么做???谢谢

4

1 回答 1

0

但我希望单击选定的选项。怎么可能?是否需要将其状态存储在数据库或任何其他解决方案中?

是的,您需要存储单选按钮的状态,这里的最佳选择是PreferenceManager

于 2013-07-18T07:19:37.960 回答