I have actions, MainActivity and settingsActivity. Because of this, I use the methods onPauseand onResumein settingsActivity. So the things that I did in the settings are saved after switching to MainActivity and back.
settingsActivity:
Here I have TextView(called "settings2") as a kind of variable and my three RadioButtons( radio0, radio1and radio2) that are inside RadioGroup. After switching to MainActivity, my program puts "0" in the file (which is saved on the SD card) if the last checkbox is selected radio0. But if the last checkbox radio1, it puts 1 in this file. And if the last checkbox radio2was checked, it puts 2 in this file. I used this in a method onPause.
Then in the method onResumeI read the text of this file and put it in TextView"settings2". After this code (still in onResume) I want to check / uncheck my own RadioButtons. So if the text TextView"settings2" is "0", check RadioButton "radio0"and the rest will not. If the text of this TextViewis "1", you should check RadioButton "radio1", but the rest will not. And if the text of this TextViewis "2", the mark RadioButton "radio2"should be checked, and the rest not. For this, I used the following two codes, but unfortunately they did not work.
First code:
if (settings2.getText().equals("0")) {
radio0.setChecked(true);
radio1.setChecked(false);
radio2.setChecked(false);
} else if (settings2.getText().equals("1")) {
radio0.setChecked(false);
radio1.setChecked(true);
radio2.setChecked(false);
} else if (settings2.getText().equals("2")) {
radio0.setChecked(false);
radio1.setChecked(false);
radio2.setChecked(true);
}
Second code:
if (settings2.getText().equals("0")) {
radioGroup1.check(R.id.radio0);
} else if (settings2.getText().equals("1")) {
radioGroup1.check(R.id.radio1);
} else if (settings2.getText().equals("2")) {
radioGroup1.check(R.id.radio2);
}
Can someone help with this little problem please? I look forward to your help!
Thanks in advance!
source
share