【问题标题】:RecyclerView item click and open another recyclerviewRecyclerView 项目单击并打开另一个recyclerview
【发布时间】:2020-01-05 16:44:02
【问题描述】:

在此处输入图像描述我有近 250 项专利项目,我想在父回收站视图中显示。单击父recyclerview的item后,它将在另一个recyclerview的每个父item下显示数百个数据。我怎么能像这张照片一样。

【问题讨论】:

  • 请在此处添加未显示的图像@Md
  • 是的。我已经添加了
  • 您需要在另一个屏幕中显示,还是如图所示在单屏中显示?
  • 我想在另一个屏幕上显示

标签: android android-recyclerview onclicklistener


【解决方案1】:

我会这样做。创建接口:

interface AdapterContract{
  fun onListItemClick(id: String) //whatever the parameter is
}

当你在Fragment1中实例化Adapter时,你可以实现这个接口:

class Fragment1 : Fragment(), AdapterContract{
  ...
  //when instantiating the adapter:
  private val adapter: MyAdapter by lazy{
      MyAdapter(this //for the interface)
  }
  //override the method of Adapter contract
}

您的适配器构造函数应如下所示:MyAdapter(adapterContract: AdapterContract) : ListAdapter<MyAdapter.MyViewHolder>(Diff_Util_SOME_OBJECT)

比在适配器 ViewHolder 中:

itemHolder?.setOnClickListener{
 adapterContract.onListItemClick(someId)
}

现在在Fragment1 中的覆盖方法中:

override method onListItemClick(id: String){
  //pass this id to the next opening fragment (like Bundles or navargs)
 //init `Fragment2` which is going to have all items, that belong to `Fragment1` selected item
}

加载数据:)

我希望您使用的是数据库或其他东西。也应该使用硬编码的数据结构,但为了安全起见:)。

【讨论】:

  • 你有这样的教程吗?
  • 我刚刚成功了。
  • 其实我是安卓开发的新手。我在哪里可以得到这个??
  • 我说的是答案。这已经是您需要的所有步骤了。
  • 其实我需要完整的过程。因为我是android开发的新手。这对我会有帮助....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-11
  • 1970-01-01
  • 2019-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多