0

I have radio button list in alert dialog where I have to select option like alarm after 10 mints, 15 mints and n mints, But when I click on one radio button and again opening a laert dialog radio button remain un-clicked but I want selected option to be clicked. how's it is possible? Is there any need to store it's state in database or any other solution?

My Activity:

 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 Activity:

 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)
{
    }

Please suggest what to do??? Thanks

Shweta
  • 1,145
  • 5
  • 18
  • 35

1 Answers1

0

but I want selected option to be clicked. how's it is possible? Is there any need to store it's state in database or any other solution?

Yes you need to store the state of the radio button, best choice here to PreferenceManager

Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
  • using database? are already using database in your application? why don't you want to use PreferenceManager? is there any concern? – Ahmad Kayyali Jul 18 '13 at 07:48
  • I am using database, Is it possible to use preferences on alert Dialog ? or it is mandatory to use menu options to use preferences? I have used in my previous project but there i have used sync option in menu options. – Shweta Jul 18 '13 at 08:12
  • no it's not mandatory all you need is to store your radio buttons stats in the preferences manager check preet answer [How to use SharedPreferences in Android to store, fetch and edit values](http://stackoverflow.com/a/11027631/488434) – Ahmad Kayyali Jul 18 '13 at 08:19