java - I am unable to uncheck radio buttons in listview -
public view getview(final int position, view convertview, viewgroup parent) {
final constructor row = buttonlist.get(position); layoutinflater inflater = layoutinflater.from( context ); view v = inflater.inflate( r.layout.breakfastitems_view, parent, false ); relativelayout relative1 = (relativelayout)v.findviewbyid(r.id.relative1); final radiobutton chbox=(radiobutton)v.findviewbyid(r.id.rb1); final radiobutton rb2=(radiobutton)v.findviewbyid(r.id.rb2); chbox.setonclicklistener(new view.onclicklistener(){ public void onclick(view v) { radiobutton chbox = (radiobutton)v; if(chbox.ischecked()){ boolean value=false; rb2.setchecked(value); rb3.setchecked(false); rb4.setchecked(false); rb5.setchecked(false); rb6.setchecked(false); } selected_total.set(position, selected_cost.get(position)); selectprice.settext(selected_total.get(position)); } }); rb2.setonclicklistener(new view.onclicklistener(){ public void onclick(view v) { if(position==1){ chbox.setchecked(false); rb3.setchecked(false); rb4.setchecked(false); rb5.setchecked(false); rb6.setchecked(false); } selected_total.set(position, selected_cost.get(position)); selectprice.settext(selected_total.get(position)); } });
here xml file code,
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <relativelayout android:id="@+id/relative1" android:layout_width="match_parent" android:layout_height="60dp"> <textview android:id="@+id/item" android:layout_width="fill_parent" android:layout_height="50dp" android:gravity="center_vertical" android:text="textview" android:textcolor="#000000" android:textsize="16dp"/> <textview android:id="@+id/price_text" android:layout_width="70dp" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/item" android:layout_alignbottom="@+id/item" android:layout_alignparentright="true" android:gravity="center" android:text="$3.20" android:textcolor="#000000"/> <radiobutton android:id="@+id/rb1" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignbaseline="@+id/item" android:layout_alignbottom="@+id/item" android:layout_toleftof="@+id/price_text"/> </relativelayout> <relativelayout android:id="@+id/relative2" android:layout_width="match_parent" android:layout_height="60dp" > <textview android:id="@+id/item2" android:layout_width="fill_parent" android:layout_height="50dp" android:gravity="center_vertical" android:text="textview" android:textcolor="#000000" android:textsize="16dp" /> <textview android:id="@+id/price_text2" android:layout_width="70dp" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/rb2" android:layout_alignbottom="@+id/rb2" android:layout_alignparentright="true" android:gravity="center" android:text="$3.20" android:textcolor="#000000" /> <radiobutton android:id="@+id/rb2" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignparenttop="true" android:layout_toleftof="@+id/price_text2" /> </relativelayout> </linearlayout>
i unable uncheck radio buttons. have posted java code , xml code.thanks in advance.
do not try checked , unchecked radiobutton pragmatically ...just put radio button in 1 radiogroup
in xml row layout file.
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="@dimen/marginten" > <radiogroup android:id="@+id/radiogroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <radiobutton android:id="@+id/radiobutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="radiobutton" /> <radiobutton android:id="@+id/radiobutton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="radiobutton" /> <radiobutton android:id="@+id/radiobutton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="radiobutton" /> </radiogroup> </linearlayout>
Comments
Post a Comment