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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With