[英]How do i open a fragment from an activity from the onClickListener of a recyclerView
I am trying to open a fragment when an item in the recyclerView is clicked,in an Activity, then pass the text of the text view from the recycler view to the fragments text view.我试图在活动中单击 recyclerView 中的项目时打开一个片段,然后将文本视图的文本从回收器视图传递到片段文本视图。 the OnClickListener is in my adapter class.
OnClickListener 在我的适配器 class 中。 i cant find a mathcing solution for this in Kotlin.
我在 Kotlin 中找不到数学解决方案。
` `
class MyViewHolder(listView:View) : RecyclerView.ViewHolder(listView){
var itemTitle : TextView
var itemDetail: TextView
init {
itemTitle = listView.findViewById(R.id.title)
itemDetail =listView.findViewById(R.id.description)
listView.setOnClickListener {v: View ->
var detailFragment: DetailFragment = DetailFragment()
}
}
}`
Do it in onBindViewHolder()
method of Adapter class在 Adapter class 的
onBindViewHolder()
方法中执行
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
hoder.itemTitle.setText(your_data_list.get(position).getTitle())
holder.itemView.setOnClickListener {
//open DetailsFragment with text right there.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.