Reputation: 5108
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();
}
Upvotes: 10
Views: 6608
Reputation: 599401
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.
Upvotes: 34