所以我看过很多Kotlin的回收站教程,但是它们似乎都是基于项目评论/联系人列表,当你被选中时,这些列表都会把你带到同一个屏幕,尽管有不同的视频文件夹内容。我想知道是否有可能使用独立的recyclerview/listview来导航,而不是导航抽屉,这似乎不适合广泛的目录。如果是这样的话,有没有关于这方面的教程?
本质上是像this这样的东西
发布于 2020-04-11 05:59:40
在您的适配器中,您可以在onBindViewHolder中的RecyclerView中的每个视图上设置一个标记,并且在单击侦听器中,您可以获取标记并根据它是哪个标记来操作。
您可以使RecyclerView适配器扩展View.onClickListener
override fun onBindViewHolder(holder: OpportunityViewHolder, position: Int) {
// Differentiate between items by having a base class that you implement for your different items
val item = getItem(position)
item.tag = when(item) {
is ThisThing -> "thisThing"
is ThatThing -> "thatThing"
is AnotherThing -> "anotherThing"
}
}
override fun onClick(v: View) {
when(v.tag) {
"thisThing" -> // do something
"thatThing" -> // something else...
}
当然,您可能希望使用枚举来表示标记的可能性,或者常量值,甚至使用类名
enum class Tag {
THIS_THING, THAT_THING...
}
companion object {
private const val THIS_THING = "THIS_THING"
...
}
// Inside classes
companion object {
val name = ThisThing::class.simpleName
...
}
https://stackoverflow.com/questions/61141425
复制相似问题