We don’t put return
statement above any other statement unless that return
is under any conditional statement. If we do that then all the statements below that would never get executed (means it would become unreachable under all circumstances) which causes the error you are getting.
Do it like this
public class TabFragmentA extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RelativeLayout rootView = (RelativeLayout) inflater.inflate(R.layout.tab_layout_a, container, false);
final RadioButton r1 = (RadioButton) rootView.findViewById(R.id.radio1);
final RadioButton r2 = (RadioButton) rootView.findViewById(R.id.radio2);
final ImageView iv1 = (ImageView) rootView.findViewById(R.id.iv1);
final ImageView iv2 = (ImageView) rootView.findViewById(R.id.iv2);
iv1.setVisibility(View.INVISIBLE);
iv2.setVisibility(View.INVISIBLE);
r1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(r1.isChecked())
{
r2.setChecked(false);
iv2.setVisibility(View.INVISIBLE);
iv1.setVisibility(View.VISIBLE);
}
}
});
r2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(r2.isChecked())
{
r1.setChecked(false);
iv1.setVisibility(View.INVISIBLE);
iv2.setVisibility(View.VISIBLE);
}
}
});
return rootView;
}
}