如何在Item Click上从FirebaseListAdapter获取obj键。 FirebaseUI [英] How to get obj key from FirebaseListAdapter on Item Click. FirebaseUI

查看:102
本文介绍了如何在Item Click上从FirebaseListAdapter获取obj键。 FirebaseUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在FirebaseUI中继承FirebaseListAdapter时,如何获得单击项目的obj键?

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屋!

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