其實我想啓用/禁用RecyclerView的特定行,以便在Adapter類中實現我的邏輯onBindViewHolder函數,但是當我應用啓用屬性比它不對我的持有人物品造成任何影響。所以任何人都可以告訴我它是如何完成的。啓用/禁用和Clickable屬性不工作在RecyclerView適配器
注:
我知道有很多類似的問題在那裏,但我想大多數人,但沒有奏效。
可見性物業工作在我夾產品
代碼:
@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 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);
}
}
嘗試父視圖(此卡視圖) –
OKY讓我試試... – techDigi
@BapusahebShinde還是同樣的問題 – techDigi