如何在Item Click上从FirebaseListAdapter获取obj键。 FirebaseUI [英] How to get obj key from FirebaseListAdapter on Item Click. FirebaseUI
问题描述
FirebaseListAdapter具有以下获取itemId的方法,但返回long。但是我需要使用默认字符串格式的对象键。
public long getItemId(int i){
返回(long)this.mSnapshots.getItem(i).getKey()。hashCode();
FirebaseListAdapter
假定您始终知道与之交互的项目的索引/位置。一旦你知道了位置,你可以调用 adapter.getRef(position)
来获取Firebase参考对象。在该引用上,您可以调用 getKey()
一个>来获得钥匙。虽然我建议只作为最后的手段。 When subclassing FirebaseListAdapter in FirebaseUI how can one get the obj key of the item clicked?
FirebaseListAdapter has the following method which gets itemId, but returns long. But I require the object key which is in the default string format.
public long getItemId(int i) {
return (long)this.mSnapshots.getItem(i).getKey().hashCode();
}
The FirebaseListAdapter
assumes that you always know the index/position of the item you are interacting with. Given the Android context this makes sense, since collection views are index based.
Once you know the position, you can call adapter.getRef(position)
to get the Firebase reference to the object. On that reference, you can call getKey()
to get the key. Although I recommend only doing that as a last resort.
这篇关于如何在Item Click上从FirebaseListAdapter获取obj键。 FirebaseUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!