0

在我的应用程序中,我与 REST API 通信以获取文件夹列表和页面列表,每个文件夹都有一个子文件夹列表(子文件夹可以是另一个文件夹或页面列表),这意味着在 1 个文件夹内我们可以找到一个层次结构文件夹,在我的文件夹列表项目中,我使用 RecycleView 创建了一个片段和布局,对于页面也是如此,所以我的问题是我找不到显示文件夹层次结构的解决方案,所以我找到了解决方案:

  1. 为文件夹的孩子创建很多片段(这不好,因为这取决于文件夹有多少孩子)
  2. 递归使用 RecycleView 但我不知道如何:/

项目计划如下:

- Folder 1
      -Folder 1.1
          -List of pages
       -Folder 1.2
       -Folder 1.2.1
           - List of Pages
       -Folder 1.2.2
            -List of Pages
 - Folder 2
    - List of pages

......

文件夹适配器

z

var onItemClick: ((Result) -> Unit)? = null
var onItemLongClick: ((Result) -> Boolean)? = null//de ty boolenn

private var folderList = emptyList<Result>()

inner class FolderViewHolder(folderItemView: View) : RecyclerView.ViewHolder(folderItemView) {
    init {
        folderItemView.setOnClickListener {
            onItemClick?.invoke(folderList[adapterPosition])
        }
        folderItemView.setOnLongClickListener {
            onItemLongClick?.invoke(folderList[adapterPosition]) == true//hna fine ajoutitr=e

        }
    }
}


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FolderViewHolder {
    return FolderViewHolder(
        LayoutInflater.from(parent.context).inflate(R.layout.folder_item_layout, parent, false)
    )
}

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: FolderViewHolder, position: Int) {
    holder.itemView.title_text.text = folderList[position].name
    holder.itemView.date_text.text = "Type :" + folderList[position].type
}

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

fun folderAdapterLoadData(newList: List<Result>) {
    folderList = newList
    notifyDataSetChanged()
}

页面适配器

class PagesAdapter : RecyclerView.Adapter<PagesAdapter.PagesViewHolder>() {
    private var pagesList = emptyList<Result>()
    var onItemClick: ((Result) -> Unit)? = null
    var url: String = ""

inner class PagesViewHolder(pagesItemView: View) : RecyclerView.ViewHolder(pagesItemView) {
    init {
        pagesItemView.setOnClickListener {
            onItemClick?.invoke(pagesList[adapterPosition])
        }
    }
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PagesViewHolder {

    return PagesViewHolder(
        LayoutInflater.from(parent.context).inflate(R.layout.page_item_layout, parent, false)
    )
}

override fun onBindViewHolder(holder: PagesViewHolder, position: Int) {
    holder.itemView.title_text.text =pagesList[position].name
    holder.itemView.date_text.text = "Type : "+pagesList[position].type
    holder.itemView.imageView
    url = pagesList[position].zone.image.url
    Picasso.get().load(url+"/0,0,4267,6694/,400/0/default.jpg").into(holder.itemView.imageViewPage)
}

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

fun pageAdapterLoadData(newList: List<Result>) {
    pagesList = newList
    notifyDataSetChanged()
}
4

0 回答 0