如何从Android中RecyclerView适配器获得项目 [英] How to get item from RecyclerView adapter in Android

查看:424
本文介绍了如何从Android中RecyclerView适配器获得项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧的code当我使用自定义的ListView适配器我可以用这个code拿到项目。

In old code when I was using ListView with custom adapter I could get item with this code.

Message msg = (Message) adapter.getItem(poistion);

现在我实现RecyclerView。如何从RecyclerView适配器得到项目?

Now I am implementing RecyclerView. How can I get item from RecyclerView adapter?

推荐答案

您必须自己实现它。

在自定义适配器添加了新的方法和你做。

Add a new method in your custom Adapter and you are done.

public Message getItem(int position) {
  return messageList.get(position);
}

这篇关于如何从Android中RecyclerView适配器获得项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆