-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
I have a scenario where I want to be able to quickly check for key existence and because of that it was desirable to use object keys as the value (like a hash table).Essentially this means I needed to be able to extend FirebaseListAdapter using a mModelClass class of type String.
To support this functionality, I modified FirebaseListAdapter with a function parseNode
private T parseNode(DataSnapshot dataSnapshot){
String key = dataSnapshot.getKey();
T newModel = null;
if(!(FirebaseListAdapter.this.mModelClass == String.class)){
newModel = dataSnapshot.getValue(FirebaseListAdapter.this.mModelClass);
}else{
newModel = (T) key;
}
return newModel;
}
Now in all of the ChildEventListener callbacks the model variable gets assigned the output of parseNode and the adapter is able to handle iterating over object keys. I just figured it's a pretty minor change to the class and it helped with my case so maybe it would be useful for other people.