In my application, I use a radiogroup in which there are several radiobutton. When selected, the radiobutton sends the name of its id to activation 2. With the second activation you can return to the first and select other radiogroup options, the question is how to return to the first activation with radiogroup Once again, the option we chose earlier, that is, if radiobutton1 is already marked isCheck (true), but do we need to return to the second activation with the given id by clicking on the already marked option? A small piece of code:

OnCheckedChangeListener rad=newOnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { but = (RadioButton) radioGroup.findViewById(checkedId); int checkedIndex = radioGroup.indexOfChild(but); SavePreferences("key", checkedIndex); name =getResources().getResourceEntryName(checkedId); intent.putExtra("sample",name); startActivity(intent); finish(); } }; 

    1 answer 1

    Alternatively, in the first activation, in onResume() , radioGroup can reset the selection of elements.

     private RadioGroup.OnCheckedChangeListener mOnCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { //делаете здесь свои дела и вызываете вторую активити } }; @Override protected void onResume() { super.onResume(); mRadioGroup.setOnCheckedChangeListener(null); mRadioGroup.clearCheck(); mRadioGroup.setOnCheckedChangeListener(mOnCheckedChangeListener); } 

    When you click the back button on the second activation, the onResume() method will be onResume() in the first activation and will reset the selection in radioGroup .

    • one
      This is not exactly the case, because when you return to the first activation, Check should remain, because if there are 20, then the user needs to remember which option he chose, and this is not for everyone, I solved the problem by adding radiobutton android for each: onClick = "clickcheck "and in java: public void clickcheck (View view) {startActivity (intent); finish (); } Thank you all for the answer and the time spent on my question, otherwise I thought I ignored everything as usual, it’s not like a bunch of answer-tellers come flying over Vladimir -