android - Checking a radioButton in RecyclerView makes other random radiobutton checked too -
im new in recyclerview , when use radiogroup
4 radiobutton
in recyclerview
.every things works fine, when scroll down in recyclerview radio button randomly checked in position layout row_mylist.xml
<radiogroup> <radiobutton android:text="radiobutton" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn_radio_test2" android:button="@null" android:drawableright="?android:attr/listchoiceindicatorsingle" android:layout_weight="1" android:gravity="right|center_vertical" android:textsize="10sp" /> <radiobutton android:text="radiobutton" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn_radio_test3" android:button="@null" android:drawableright="?android:attr/listchoiceindicatorsingle" android:layout_weight="1" android:gravity="right|center_vertical" android:textsize="10sp" /> <radiobutton android:text="radiobutton" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn_radio_test1" android:layout_weight="1" android:button="@null" android:drawableright="?android:attr/listchoiceindicatorsingle" android:gravity="right|center_vertical" android:textsize="10sp" /> <radiobutton android:text="radiobutton" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn_radio_test4" android:layout_weight="1" android:button="@null" android:drawableright="?android:attr/listchoiceindicatorsingle" android:gravity="right|center_vertical" android:textsize="10sp" /> <radiogroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/radiogp_testi" android:layout_margintop="20dp" android:layout_marginbottom="10dp" android:layout_marginleft="5dp" android:layout_marginright="5dp" > </radiogroup>
my adapter code
public class adapterquiz extends recyclerview.adapter<adapterquiz.myviewholder> { private activity context; private arraylist<hashmap<string,string>>quizs=new arraylist<>(); private static hashmap<string,string>hashmap; public adapterquiz(final activity context, arraylist<hashmap<string,string>>quizs){ this.context=context; this.quizs=quizs; } @override public myviewholder oncreateviewholder(viewgroup parent, int viewtype) { view view; view= layoutinflater.from(context).inflate(r.layout.row_soalat,parent,false); return new myviewholder(view); } @override public void onbindviewholder(final myviewholder holder, final int position) { hashmap=new hashmap<>(); hashmap=quizs.get(position); holder.rgtesti.setoncheckedchangelistener(new radiogroup.oncheckedchangelistener() { @override public void oncheckedchanged(radiogroup radiogroup, int i) { switch (i){ case r.id.btn_radio_test1: //show toast break; case r.id.btn_radio_test2: //show toast break; case r.id.btn_radio_test3: //show toast break; case r.id.btn_radio_test4: //show toast break; } } }); } }
your on wrong track... wrap radio buttons inside radio group.
Comments
Post a Comment