实际上我想启用/禁用RecyclerVIEw的特定行,所以在Adapter Class中我在onBindVIEwHolder函数中实现我的逻辑但是当我应用Enabled Property时它不会对我的holder项产生任何影响.
所以任何人都可以告诉我它是如何完成的.
注意:
>我知道有很多类似的问题,但我尝试了大部分但是没有用.
> Visiblity Property正在处理我的持有人项目
代码:
@OverrIDepublic 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); }}
解决方法:
检查您是否实际上点击了您认为自己点击的视图.您可能会将要尝试抑制点击的视图覆盖到另一个视图,因此,即使您禁用了您感兴趣的视图,您也会看到覆盖视图中的点击.您可以检查传递给单击处理程序的视图的ID以检查它.
如果是这种情况,则设置其他属性(如背景颜色和Alpha)仍然有效.
总结以上是内存溢出为你收集整理的android – 启用/禁用和可点击的属性在RecyclerView适配器中不起作用全部内容,希望文章能够帮你解决android – 启用/禁用和可点击的属性在RecyclerView适配器中不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)