Actually i want to Enabled/Disable a specific row of RecyclerView so in Adapter Class i implement my Logic in onBindViewHolder function but when i apply the Enabled Property than it doesn't create any effect on my holder item. So can anyone tell me how it is done.
Note:
I know there are many similar questions out there but i tried most of them but it didn't work.
Visiblity Property is working on my holder Item
Code :
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
RegsiteredCarDisplayItem displayItem = displayItems.get(position);
holder.modelName.setText(displayItem.getMyOwnedCar().getCarModelName()); if(selected_usersList.contains(displayItems.get(position).getMyOwnedCar()))
holder.childView.setBackgroundColor(ContextCompat.getColor(context, R.color.buttonbackground));
else
holder.childView.setBackgroundColor(ContextCompat.getColor(context, R.color.textViewBackground));
if (displayItems.get(position).getVisible()){
Log.d("AIAITRUE", String.valueOf(displayItems.get(position)));
holder.childView.setEnabled(true);
holder.childView.setClickable(true);
}else{
// here i want to Disable my Holder View but the below line is not working, but i use another property like alpha instaed of Enabled property than property(refrence alpha) is working
holder.childView.setEnabled(false);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
>
<RelativeLayout
android:id="@+id/parentView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false">
<RelativeLayout
android:id="@+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding"
android:layout_marginBottom="@dimen/padding"
android:orientation="vertical"
android:clickable="false"
tools:ignore="UselessParent">
<ImageView
android:id="@+id/icons"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_alignBottom="@id/linearlayout"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="false"
android:layout_marginEnd="@dimen/margin_five"
android:layout_marginRight="@dimen/margin_five"
android:layout_marginBottom="-15dp"
android:background="@color/colorAccent"
android:clickable="false"
android:adjustViewBounds="true"
tools:ignore="RtlHardcoded"/>
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icons"
android:layout_marginBottom="@dimen/padding"
android:orientation="horizontal"
android:clickable="false"
tools:ignore="RtlHardcoded">
<TextView
android:id="@+id/modelNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:gravity="start"
android:clickable="false"
android:textSize="@dimen/text_size"
android:drawablePadding="@dimen/drawable_padding"
android:drawableTint="@color/buttonbackground"
tools:ignore="RtlSymmetry"
tools:targetApi="m"
android:textColor="@color/colorAccent"/>
</LinearLayout>
<TextView
android:id="@+id/registration_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearlayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="@dimen/left_margin_registration_number"
android:layout_marginStart="@dimen/left_margin_registration_number"
android:clickable="false"
android:textColor="@color/text_color"/>
<ImageView
android:id="@+id/next_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/linearlayout"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="false"
android:layout_marginBottom="-10dp"
android:clickable="false"
android:foregroundGravity="right"
android:tint="@color/buttonbackground"
app:srcCompat="@drawable/ic_next"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
VieHolder Class:
class ViewHolder extends RecyclerView.ViewHolder{
TextView carName,modelName,registrationNumber; View cardView;
RelativeLayout childView;ImageView imageView; ImageView imageicon;
public ViewHolder(View itemView) {
super(itemView);
Typeface custom_font = Typeface.createFromAsset(context.getAssets(), "fonts/helvetica-neue-ce-55-roman.ttf");
Typeface custom_fonts = Typeface.createFromAsset(context.getAssets(), "fonts/helvetica-neue-ce-35-thin.ttf");
cardView = itemView.findViewById(R.id.cardView);
modelName=(TextView)itemView.findViewById(R.id.modelNumber);
registrationNumber=(TextView)itemView.findViewById(R.id.registration_number);
childView =(RelativeLayout)itemView.findViewById(R.id.parentView);
imageView=(ImageView) itemView.findViewById(R.id.next_icon);
imageicon=(ImageView)itemView.findViewById(R.id.icons);
modelName.setTypeface(custom_font);
registrationNumber.setTypeface(custom_fonts);
}
}
Check that you are actually clicking on the view you think you are clicking on. You may be overlaying the view for which you are trying to suppress clicks with another view so, even if you disabled the view you are interested in, you will see clicks from the overlaying view. You can check the id of the view passed into the click handler to check this out.
If this is the case, then setting other attributes such as background color and alpha would still work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With