我在警告对话框中有单选按钮列表,我必须在10分钟,15分钟和n分钟后选择警报之类的选项,但是当我点击一个单选按钮并再次打开一个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();
}
});
BroadCastReceiver活动:
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)
{
}
请建议做什么???感谢
答案 0 :(得分:0)
但我希望点击选定的选项。怎么可能?是 有没有必要将它的状态存储在数据库或任何其他解决方案中?
是的,你需要存储单选按钮的状态,这里最好选择PreferenceManager