final View rootView = inflater.inflate(R.layout.activity_search, container,false);
final LinearLayout l = (LinearLayout)inflater.inflate(R.layout.activity_search, container, false);
the problem is here. You are inflating twice the same layout and returnin l
, but attach the OnCheckedChangeListener
on the RadioGroup you retrieve with rootView
. It should be
RadioGroup radios = (RadioGroup) l.findViewById(R.id.radios);
instead of
RadioGroup radios = (RadioGroup) rootView.findViewById(R.id.radios);
Also inside onCheckedChanged
you should remove l.addView
otherwise you application wil crash because the TextView
has already as parent l