6

我是 android 开发新手。我正在使用这个库https://github.com/chthai64/SwipeRevealLayout在我的 recyclerview 上实现 swipelayout。

但是,它只能滑动打开和关闭,但我想实现当一个项目被滑动打开然后单击任何项​​目将关闭当前打开的项目。我只是无法弄清楚它是如何工作的。

如果我的主题问题与我所描述的不符,我很抱歉,我不是以英语为母语的人。

我可以设置 ViewBinderHelper.setOpenOnly(true) 。它一次只能刷一个项目。我试图通过 holder.swipelayout.isOpen 测试 swipelayout 是打开还是关闭,但它什么也没做。

任何想法或帮助将不胜感激,谢谢。

这是我的适配器类

class ReturnAdapter(val context : Context , val deliveryinfo : MutableList<BookingInfo>) : RecyclerView.Adapter<ReturnAdapter.MyViewHolder>() {

private val viewbinderhelper = ViewBinderHelper()
init {
    viewbinderhelper.setOpenOnlyOne(true)
 }

 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
     val view=LayoutInflater.from(context).inflate(R.layout.return_model_layout, parent, false)
    return MyViewHolder(view)
}

override fun getItemCount(): Int {
    return deliveryinfo.size
}

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
    val deliveryinformation = deliveryinfo[position]
    holder.setData(deliveryinformation)
    viewbinderhelper.bind(holder.swipelayout, deliveryinformation.booking_id.toString())

  }  

    inner class MyViewHolder(itemView:View):RecyclerView.ViewHolder(itemView) {

   val swipelayout : SwipeRevealLayout = 
   itemView.findViewById(R.id.swipelayout)
}

我的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
     <com.chauthai.swipereveallayout.SwipeRevealLayoutandroid:layout_height="match_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  app:mode="same_level"
  app:dragEdge="right"
  android:id="@+id/swipelayout">

        <!-- Your secondary layout here -->
<LinearLayout android:layout_width="70dp"
              android:id="@+id/deletereturn"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:clickable="true"
              android:foreground="? 
              android:attr/selectableItemBackground"
              android:gravity="center"
              android:background="@color/red">

    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
               android:src="@drawable/ic_delete_white_36dp"/>
</LinearLayout>

         <!-- Your main layout here -->




   <LinearLayout android:layout_width="match_parent" 
    android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_marginHorizontal="30dp"
                      android:gravity="center"
                      android:layout_centerVertical="true">
            <pl.droidsonroids.gif.GifImageView
                    android:layout_width="36dp"
                    android:layout_gravity="center"
                    android:layout_height="36dp"
                    android:id="@+id/packaging"
                   android:src="@drawable/redmarkcheck"</LinearLayout></com.chauthai.swipereveallayout.SwipeRevealLayout>
4

0 回答 0