android - Radio Button setOnChangeListener not working inside fragment -
i want check whether radio button checked do. inside fragment not working cannot figure out because of why? if 1 can appreciate much!
my fragment:
public class onefragment extends fragment { radiogroup radiofanstatus; radiobutton radiobuttonon; radiobutton radiobuttonoff; view inflateview; tabdisplay tabdisplay; public onefragment() { // required empty public constructor } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment inflateview=inflater.inflate(r.layout.fragment_one, container, false); radiofanstatus = (radiogroup)inflateview.findviewbyid(r.id.radioonoff); radiobuttonon=(radiobutton)inflateview.findviewbyid(r.id.radiofanon); radiobuttonoff=(radiobutton)inflateview.findviewbyid(r.id.radiofanoff); radiofanstatus.setoncheckedchangelistener(new radiogroup.oncheckedchangelistener() { @override public void oncheckedchanged(radiogroup group, int checkedid) { toast.maketext(getcontext(),"on",toast.length_short).show(); // log.e("",""+checkedid); toast.maketext(getcontext(),"on"+checkedid+"",toast.length_short).show(); // checkedid radiobutton selected if(checkedid ==r.id.radiofanon) { toast.maketext(getcontext(),"on"+checkedid+"",toast.length_short).show(); ((tabdisplay)getactivity()).functionfanon(); log.e("","on"); } else if(checkedid ==r.id.radiofanoff) { toast.maketext(getcontext(),"off"+checkedid+"",toast.length_short).show(); ((tabdisplay)getactivity()).functionfanoff(); log.e("","off"); } else { } } }); return inflater.inflate(r.layout.fragment_one, container, false); } }
this xml related fragment:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="change staus" android:textsize="40dp" android:layout_centerinparent="true"/> <radiogroup android:id="@+id/radioonoff" android:layout_width="wrap_content" android:layout_height="wrap_content" > <radiobutton android:id="@+id/radiofanon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="on" /> <radiobutton android:id="@+id/radiofanoff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="off" /> </radiogroup>
try change
return inflater.inflate(r.layout.fragment_one, container, false);
to
return inflateview;
now inflating layout twice.
Comments
Post a Comment