Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to check what is value in <code>sharedpreferences</code>? As per value you need to set </p> <pre><code>radioButton.setEnabled(false). </code></pre> <p>Post your code, I will explain you more about how to handle this.</p> <p><strong>Edit :</strong></p> <p>As per your code, You need to check checked states when user click on Submit button. </p> <p>You can do like following.</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.temp); SharedPreferences _mypref = getApplicationContext() .getSharedPreferences("mypref", 0); // &lt;--- 0 - for private Editor editor = _mypref.edit(); first = _mypref.getString("first", ""); second = _mypref.getString("second", ""); Log.e("=first==&gt;", "===&gt;" + first); Log.e("=second==&gt;", "===&gt;" + second); rbtnTeacher1_1 = (RadioButton) findViewById(R.id.radioMale); rbtnTeacher1_2 = (RadioButton) findViewById(R.id.radioFemale); if (first.length() &gt;= 0) { if (first.equals("true")) { rbtnTeacher1_1.setChecked(true); } else { rbtnTeacher1_1.setChecked(false); } } if (second.length() &gt;= 0) { if (second.equals("true")) { rbtnTeacher1_2.setChecked(true); } else { rbtnTeacher1_2.setChecked(false); } } } public void onCheck(View v) { if (rbtnTeacher1_1.isChecked() == true) { SharedPreferences _mypref = getApplicationContext() .getSharedPreferences("mypref", 0); // &lt;--- 0 - for private Editor editor = _mypref.edit(); editor.putString("first", "true"); editor.commit(); } else { SharedPreferences _mypref = getApplicationContext() .getSharedPreferences("mypref", 0); // &lt;--- 0 - for private Editor editor = _mypref.edit(); editor.putString("first", "false"); editor.commit(); } if (rbtnTeacher1_2.isChecked() == true) { SharedPreferences _mypref = getApplicationContext() .getSharedPreferences("mypref", 0); // &lt;--- 0 - for private Editor editor = _mypref.edit(); editor.putString("second", "true"); editor.commit(); } else { SharedPreferences _mypref = getApplicationContext() .getSharedPreferences("mypref", 0); // &lt;--- 0 - for private Editor editor = _mypref.edit(); editor.putString("second", "false"); editor.commit(); } } </code></pre> <p>And your xml looks like...</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:baselineAligned="true" android:orientation="vertical" &gt; &lt;RadioGroup android:id="@+id/radioSex" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;RadioButton android:id="@+id/radioMale" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="male" /&gt; &lt;RadioButton android:id="@+id/radioFemale" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="female" /&gt; &lt;/RadioGroup&gt; &lt;Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="onCheck" android:text="Check" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Select radio any of them, click on check button. Now when you come again to your activity you can see selected radio button which you checked.</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload