繁体   English   中英

如何在 Firebase Android 上的 recyclerView 中获取对象的唯一 ID?

[英]How to get object's unique id within a recyclerView on Firebase Android?

我正在使用 recyclerView 来显示 Firebase 数据库的一些对象。 这些对象不是用户。 我需要的是在单击时获取对象的键。 像holder.getKey() 之类的东西。 我正在使用 FirebaseRecyclerOptions 和 FirebaseRecyclerAdapter,所以我没有对象列表。 只是一个参考。 有任何想法吗?

您可以在onBindViewHolder尝试以下onBindViewHolder

 String keyId = this.getRef(position).getKey();

getRef(position)将返回引用的源位置, getKey()将检索节点。

你可以查看github repo中的代码:

https://github.com/firebase/FirebaseUI-Android/blob/master/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java#L113

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM