问题描述
有什么办法在外面适配器一个特定的位置,以获得RecyclerView的项目。例如在ListView中我们可以这样做:
Is there any way to get an item of the RecyclerView at a particular position outside the adapter. e.g in ListView we could do:
listView.getItem(position);
我们能做到这一点与RecyclerView?也就是保持提供的数据列表的顺序?
Can we do this with RecyclerView ? and also is the order of provided data list maintained ?
推荐答案
您可以将自己的方法添加到 RecyclerView
或我会建议在 RecyclerView .Adapter
本身。
You can add your own method to RecyclerView
or I would suggest the RecyclerView.Adapter
itself.
例如,对于ListView控件,您有:
For instance, for ListView, you have:
@Override
public Object getItem(int position) {
return listData.get(position);
}
您可以添加同样的事情到你的 RecylcerView.Adapter
或访问另一种方式通过添加一个简单的方法,以你的 RecylcerView.Adapter
:
You can add the same thing to your RecylcerView.Adapter
or access it another way by adding a simple method to your RecylcerView.Adapter
:
public List<Model> getList() {
return this.mModel;
}
使用这样的:
recyclerView.getAdapter().getList().get(position)
这篇关于RecyclerView机器人:在特定的位置获得一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!