![](/img/trans.png)
[英]android how get item by position from RecyclerView extend ListAdapter
[英]How get item by position from RecyclerView ListAdapter?
我有一個使用自定義ListAdapter的自定義對象的RecyclerView
。 有沒有一種方法可以從Activity中獲取Item在適配器中的位置,或者如何訪問包含列表?
有沒有一種方法可以從Activity中獲取Item在適配器中的位置,或者如何訪問包含列表?
您需要在自定義列表適配器中聲明一個方法,該方法公開您在構造函數中提供的基礎列表。
像這樣:
List<MyItem> myList = new List<MyItem>()
MyCustomListAdapter mAdapter = new MyCustomListAdapter(myList);
在MyCustomListAdapter構造函數中,將您的列表分配給字段mInternalList
並聲明一個方法:
public List<MyItem> getInternalList(){
return mInternalList;
}
之后,您可以使用所有列表實用程序方法來檢索元素的索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.