2016-08-03 3 views
-1

RecyclerView_item.xmlкогда элемент щелкните recyclerview проницаемым пункта щелкнул эффекты должны исчезнуть

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/overview_frag_txt_color" 
    android:padding="@dimen/dimen_2"> 

     <com.custom.SquareLayout 
      android:id="@+id/squareLayout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:orientation="vertical"> 


      <CheckBox 
       android:id="@+id/chkbox" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:checked="true" 
       android:paddingRight="10dp" 
       android:layout_margin="@dimen/dimen_5"/ 

     </com.custom.SquareLayout> 

MainActivity.xml

<android.support.v7.widget.RecyclerView 
        android:id="@+id/addresslist" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/overview_frag_txt_color" 
        android:divider="@android:color/transparent" 
        android:dividerHeight="10.0sp" 
        android:fillViewport="true" 
        android:padding="@dimen/dimen_5" 
        android:scrollbars="none" /> 

Я, имеющий три пункта в моем recyclerview. Когда щелкнут первый элемент, отметьте checkbox, а затем нажмите второй элемент. Я хочу, чтобы checkbox из 1-го предмета не был снят.

ответ

0

вы должны попробовать RadioButtons вместо CheckBoxes.

Отметьте это сообщение Select only one checkbox! Надеюсь это поможет!

0

Что вы можете сделать, это на onChecked хранилище событий положение галочку в наборе данных в глобальной переменной и вызова notifydatasetchanged и onbindViewHolder функция

public void onBindViewHolder(ViewHolder holder, int position) { 
    holder.checkBox.setChecked(selectedPostion==position); 
} 

() В классе viewHolder

checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{ 
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
    { 
     if (isChecked) 
     { 
      selectedPostion = getAdapterPostion(); 
      notifydatasetChanged() 
     } 

    } 
}); 
+0

notifdatasetchanged в моей деятельности или еще? пожалуйста, вы можете уточнить –

Смежные вопросы