Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get obj key from FirebaseListAdapter on Item Click. FirebaseUI

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();
}
like image 348
srinivas Avatar asked Oct 07 '15 16:10

srinivas


1 Answers

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.

like image 111
Frank van Puffelen Avatar answered Nov 03 '22 15:11

Frank van Puffelen