Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I disable radio buttons or radio groups using sharedpreferences?
    text
    copied!<p>I already tried these set of codes:</p> <pre><code>radioButton.setEnabled(false); radioButton.setClickable(false); </code></pre> <p>but it didn't work for me because when I tried to go back again to the activity with radio buttons, it will be clickable again.</p> <p>What I want is that when I click it once , it will not be clickable again even if I tried to go back to the activity.</p> <p>These were the codes of my activity</p> <pre><code>public class TeacherSideQuestion extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.question1); Button btnNext = (Button) findViewById(R.id.btnNext); Button btnCheck = (Button) findViewById(R.id.btnCheckTeacher1); btnNext.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(v.getContext(), TeacherSideQuestion2.class); startActivityForResult(intent, 0); } }); btnCheck.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub SharedPreferences my_preferences = PreferenceManager .getDefaultSharedPreferences(getApplication()); SharedPreferences.Editor editor = my_preferences.edit(); RadioButton rbtnTeacher1_1 = (RadioButton) findViewById(R.id.rbtnTeacher1_1); RadioButton rbtnTeacher1_2 = (RadioButton) findViewById(R.id.rbtnTeacher1_2); RadioButton rbtnTeacher1_3 = (RadioButton) findViewById(R.id.rbtnTeacher1_3); if (rbtnTeacher1_1.isChecked()) { Toast.makeText(TeacherSideQuestion.this, "Correct", Toast.LENGTH_SHORT).show(); rbtnTeacher1_1.setClickable(false); rbtnTeacher1_2.setClickable(false); rbtnTeacher1_3.setClickable(false); if (rbtnTeacher1_1.isChecked()) { editor.putInt("key1", 1); } else { editor.putInt("key1", 0); } editor.commit(); } else if (rbtnTeacher1_2.isChecked()) { Toast.makeText(TeacherSideQuestion.this, "Incorrect", Toast.LENGTH_SHORT).show(); rbtnTeacher1_1.setTextColor(Color.RED); rbtnTeacher1_1.setClickable(false); rbtnTeacher1_2.setClickable(false); rbtnTeacher1_3.setClickable(false); if (rbtnTeacher1_2.isChecked()) { editor.putInt("key1", 0); } editor.commit(); } else if (rbtnTeacher1_3.isChecked()) { Toast.makeText(TeacherSideQuestion.this, "Incorrect", Toast.LENGTH_SHORT).show(); rbtnTeacher1_1.setTextColor(Color.RED); rbtnTeacher1_1.setClickable(false); rbtnTeacher1_2.setClickable(false); rbtnTeacher1_3.setClickable(false); if (rbtnTeacher1_3.isChecked()) { editor.putInt("key1", 0); } editor.commit(); } else { return; } } }); } } </code></pre>
 

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