My Database:
{
"Shops": {
"Title": {
"1": "Footlocker",
"2": "Nike Store",
"3": "Adidas Store"
},
"Lat": {
"1": "123",
"2": "123",
"3": "123"
},
"Lon": {
"1": "123",
"2": "123",
"3": "123"
}
}
}
The numbers "1","2" and "3" represent a shop. For example "1" shop has "Footlocker" for title and "123" latitude (probably this should be a number, but that's not my problem).
My goal is to get all the titles in a Hashmap<String,String>
(key would be "1"... value "Footlocker" etc...)
So I create a reference to "Title" key in database and add the listener,
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Shops").child("Title");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
HashMap<String,String> map = (HashMap<String,String>) dataSnapshot.getValue();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
As you can imagine the above code throws an exception because an ArrayList cannot be cast to a HashMap.
My question is, shouldn't I be getting a HashMap instead with the numbers as keys and the titles as values?