android - How do I deselect/uncheck all checkbox buttons when one is selected? -
i have toggle set in java code button in xml. code follows:
@override public void onclick(final view view) { switch (view.getid()) { case r.id.selectable_text: if(view instanceof checkedtextview){ categorycheckablerow checkablerow = ((checkedtextview)view).getcategorycheckablerow(); togglecategoryrow(view, checkablerow); log.d("newsdash","i toggling in dash onclick"); if (!mcategoriesset.add(checkablerow)) { mcategoriesset.remove(checkablerow); } mdonebutton.setenabled(!mcategoriesset.isempty()); } return; case r.id.button_done: sendcategoriestoactivity(); ((dashboardmanagenewscategoriesactivity) getactivity()).updatecategoriesmap(mcategoriesset); break; default: }
}
i planning uncheck other "checks" when currect checkbox selected. have checkboxes 1 ,2 , 3, if check 1 want 2 , 3 unchecked , on. there way can achieve above code? (if cursor ( or possibly view). getcursor or currentposition ) = current checkbox selected ) { uncheck other checkboxes except current one} ?
also here's toggle row:
private void togglecategoryrow(final view view, final categorycheckablerow checkablerow) { final checkedtextview textview = (checkedtextview) view; textview.toggle(); checkablerow.setselected(textview.ischecked()); }
here;s corresponding xml file (for reference):
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/altercolor2" android:orientation="vertical"> <scrollview android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/altercolor2" android:orientation="vertical" > <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:id="@+id/button_top_news" android:layout_width="match_parent" android:layout_height="@dimen/manage_news_btn_ht" android:layout_marginleft="2dp" android:layout_marginright="2dp" android:background="@drawable/manage_market_category_btnbg" android:gravity="left|center_vertical" android:paddingleft="10dp" android:drawablepadding="10dp" android:text="@string/button_top_news" android:textcolor="#cccccc" android:textsize="@dimen/title" android:drawableleft="@drawable/arrow_expand_collapse"/> </relativelayout> </linearlayout> </,... etc
i'm not sure initializing checkboxes
i'm not sure put this. when create them, add them arraylist
like
//initialize arraylist arraylist<checkbox> checkarray = new arraylist<checkbox>(); // add checkboxes list checkarray.add(acheckbox);
then in click event
for(i=0; i<checkarray.size(); i++) { if (checkarray.get(i) != (checkbox)v) // assuming v view param passed in checkarray.get(i).setchecked(false); }
this written better i'm not sure how rest of code looks should give idea.
Comments
Post a Comment