I have some data that's set up similar to this:
Users
-1
--name:Tom
--city:NYC
-2
--name:Dick
--city:LA
-3
--name:Harry
--city:Boston
I'm displaying the "name" fields in an Android app using a listview, then setting an on click listener to open up another page with more details. Right now, I'm just passing the position of the clicked item and adding 1 to get the correct parent node to insert into the reference for the clicked Firebase data set. This works fine, but if I want to add more sets in the future, I have to insert it in the proper place and renumber everything so that it all stays in order.
Is there a way to get the parent of the particular item I clicked on? I know Firebase has the getParent()
method, but I can't figure out how to use it. getKey()
might work, too, but again, I don't know how to use it. I can get the key for the reference, but that just returns "Users", as expected. I don't know how to tell Firebase I'm only looking for the key of that one particular child.