title: check if radio button is checked using shared preferences
body: <p>i am able to save the checked radio button using shared preference and load preferences every time app starts but i want to add some code to the radio buttons i.e check if a radio button is checked and perform an action such as showing a toast for each radio button individually .the action should not fire every time the activity starts because im trying to set notification after a specific period using AlarmManager, so calling the method again would reset it</p>
  
  <pre><code>package com.example.radiogroup;
  
  import android.os.Bundle;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.RadioGroup.OnCheckedChangeListener;
  import android.widget.TextView;
  import android.app.Activity;
  import android.content.SharedPreferences;
  
  public class MainActivity extends Activity {
  
   RadioGroup radioGroup;
   TextView textCheckedID, textCheckedIndex;
  
   final String KEY_SAVED_RADIO_BUTTON_INDEX = "SAVED_RADIO_BUTTON_INDEX";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
          radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);
  
          textCheckedID = (TextView)findViewById(R.id.checkedid);
          textCheckedIndex = (TextView)findViewById(R.id.checkedindex);
  
          LoadPreferences();
      }
  
      OnCheckedChangeListener radioGroupOnCheckedChangeListener =
        new OnCheckedChangeListener(){
  
      @Override
      public void onCheckedChanged(RadioGroup group, int checkedId) {
  
       RadioButton checkedRadioButton = (RadioButton)radioGroup.findViewById(checkedId);
       int checkedIndex = radioGroup.indexOfChild(checkedRadioButton);
  
       textCheckedID.setText("checkedID = " + checkedId);
       textCheckedIndex.setText("checkedIndex = " + checkedIndex);
       SavePreferences(KEY_SAVED_RADIO_BUTTON_INDEX, checkedIndex);
      }};
  
   private void SavePreferences(String key, int value){
    SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putInt(key, value);
    editor.commit(); 
   }
  
   private void LoadPreferences(){
    SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
    int savedRadioIndex = sharedPreferences.getInt(KEY_SAVED_RADIO_BUTTON_INDEX, 0);
    RadioButton savedCheckedRadioButton = (RadioButton)radioGroup.getChildAt(savedRadioIndex);
    savedCheckedRadioButton.setChecked(true);
   }
  }
  
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity" &gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" /&gt;
  
      &lt;RadioGroup
          android:id="@+id/radiogroup"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
          &lt;RadioButton
              android:id="@+id/option1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Option 1" /&gt;
          &lt;RadioButton
              android:id="@+id/option2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Option 2" /&gt;
          &lt;RadioButton
              android:id="@+id/option3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Option 3" /&gt;
      &lt;/RadioGroup&gt;
  
      &lt;TextView
          android:id="@+id/checkedid"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
      &lt;TextView
          android:id="@+id/checkedindex"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>i have tried </p>
  
  <pre><code>if(jRadioButton1.isSelected()){
          jTextField1.setText("Welcome");
      }
      else if(jRadioButton2.isSelected()){
          jTextField1.setText("Hello");
      }
  </code></pre>
  
  <p>but it doesnt perform any action</p>