2
I created a simple project, and I realized that the RadioButton
does not change the text when rotating the screen. I created 2 functions a call setText()
and the other setText2()
with different contents, the setText()
is called when savedInstance
is null and the other when it is not null, android enters the setText2()
normally and arrow the text but does not change visually.
I tried to give request and invalidate and did not solve, it would be a component bug?
public class SampleFragment extends Fragment {
private RadioButton optA, optB,optC,optD;
private static final String TAG = "SampleFragment";
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG,"onCreate");
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.i(TAG, "onCreateView");
View view = inflater.inflate(R.layout.fragment_sample,container,false);
optA = (RadioButton) view.findViewById(R.id.optA);
optB = (RadioButton) view.findViewById(R.id.optB);
optC = (RadioButton) view.findViewById(R.id.optC);
optD = (RadioButton) view.findViewById(R.id.optD);
Button btnSetText = (Button) view.findViewById(R.id.btn_settext);
btnSetText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setText2();
}
});
if(savedInstanceState == null){
setText();
}
else{
setText2();
}
return view;
}
@Override
public void onPause() {
super.onPause();
Log.i(TAG,"onPause");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i(TAG, "onDestroy");
}
@Override
public void onResume() {
super.onResume();
Log.i(TAG,"onResume");
}
private void setText2(){
optA.setText("A1");
optB.setText("B2");
optC.setText("C3");
optD.setText("D4");
}
private void setText(){
optA.setText("A");
optB.setText("B");
optC.setText("C");
optD.setText("D");
}
}
Github of the project: https://github.com/guilhermehrcosta/Radio-Group-Bug
Put the code directly into the question.
– ramaral
Ready! I put :D
– Guilherme Costa