I have a toggle set in my java code for a button in xml. The code is as 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 am 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 am planning to uncheck all other "checks" when my currect checkbox is selected. say i have checkboxes 1 ,2 and 3, if I check 1 I want 2 and 3 to be unchecked and so on. Is there a way I can achieve this with my above code? Say (if cursor ( or possibly view). getcursor or currentposition ) = current checkbox selected ) { uncheck all other checkboxes except current one} ?
Also here's the toggle row:
private void toggleCategoryRow(final View view, final CategoryCheckableRow checkableRow) {
final CheckedTextView textView = (CheckedTextView) view;
textView.toggle();
checkableRow.setSelected(textView.isChecked());
}
Here;s the 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