我有一个包含RecyclerView的ListItems,如下所示:
pagerecycler.xml:
<com.tscriber.scriblett.views.PageRecyclerView
android:id="@+id/page_recycler_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:listitem="@layout/infinity_page_list_item" />infinity_page_list_item.xml
<ImageView
android:id="@+id/memo_page_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/memo_page_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>使用Kotlin合成技术,从父片段中我可以使用ListItem和memo_page_image?.visibility = View.INVISIBLE将那些ImageViews变为可见的或不可见的。
但是这种合成只会使ImageView在first ListItem中变得不可见。是否可以使用合成材料来打开和关闭ImageView中的n to ListItem?有点像memo_page_image[2]?.visibility = View.INVISIBLE,但不是那样的,因为这不起作用。
当然,我不一定要用合成材料。如果合成药物是不可能的,我该怎么做呢?
过去,我一直在处理ListAdapter回调数组,但对我来说,这一直是一种杂乱无章的做法,所以我正在寻找一种更优雅的方法。
提前感谢
约翰
发布于 2019-08-15 02:44:05
在recyclerView ViewHolder中,使用Kotlin Syn合,只需尝试如下:
itemView.memo_page_image?.visibility = View.INVISIBLE
发布于 2019-08-15 03:14:36
Kotlin合成物只适用于ViewBinding。它使丑陋的findViewById()离开并缓存视图,以防止多个查找视图的调用(如Adapter中的)。因此,它在RecyclerAdapter配置中不起任何作用。
如果您想在RecyclerView中更改n‘’th项,您不能只使用findViewByPosition(),因为如果第n项在屏幕上不可见,它将返回null。因此,作为一个完整的证明解决方案,您只需更改您的数据集中这个特定位置(可能是一个布尔值,是否显示为真/假),然后使用notifyItemChanged(postion)并在onBindViewHolder()中处理它。大致如下:-
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
if(show){
memo_page_image?.visibility = View.VISIBLE
}else{
memo_page_image?.visibility = View.INVISIBLE
}
}https://stackoverflow.com/questions/57504229
复制相似问题