0
Follow
0
View

How to get currently selected item position in RecyclerView?

ddhhhnj 注册会员
2023-01-24 18:49

I'm Java Developer so I cannot code with Kotlin but I'll show you how to get any view's position in RecyclerView

holder.itemView.setOnClickListener(view -> {
            Toast.makeText(context, "This is position of your Every ItemViews", Toast.LENGTH_SHORT).show();
        });

In your onBindViewHolder use this code holder.itemView.setOnClickListener and create new click listener. Here you can get the position of your items by coding and you can check by adding Toast. your code lookalike below:-

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {

        val item = list[position]

        holder.itemView.findViewById(R.id.task).text = item.task
        holder.itemView.findViewById(R.id.taskDescription).text = item.task_Details
holder.itemView.setOnClickListener(view -> {
            Toast.makeText(context, "This is position of your Every ItemViews", Toast.LENGTH_SHORT).show();
        });
    }

Make sure to change JAVA to Kotlin of my code. If you any problem is causing, Let me know

About the Author

Question Info

Publish Time
2023-01-24 18:49
Update Time
2023-01-24 18:49

Related Question

.Net core - Nuget恢复运行时文件

Strtotime从while变量显示错误的结果

PyTorch将' nan '替换为列级最大值

pytorch问题,运行错误

我想问下cin.getline(a[i])这么写对不对

使用vue3和vite在Storybook装饰器中的Vuetify3组件

没有类型为Zero[DenseVector[Double]] [duplicate]的隐式参数

"TypeError:将循环结构转换为JSON"与GET请求

burp This message is too large to display

使用QQuickWidget窗口时、绑定的信号想传string出来怎么办