user3757775 user3757775 - 7 months ago 30
Android Question

Setting name for list in class on firebase

I am using firebase in an android application where I have a house that has a list of rooms. I am trying to find out how to use the name of the room as the value for the child rather than the 0 and 1.

The database structure is below

Database Structure

Answer Source

You need to use a Map<StringRoomName,RoomDetailsClass> this will show StringRoomName in place of 0 and RoomDetailsClass as json object value. where StringRoomName = String

   class Room{
    //your other members
    Map<String,RoomDetailsClass> roomMap;
    // gettes and setters or constructor for initialization

    class RoomDetailsClass{

    //your room details


and upload it using

if (isDataValidatied()) {
                mDatabase.push().setValue(roomObject, new DatabaseReference.CompletionListener() {
                    public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                        if (databaseError == null) {
                            makeToast("One entry created successfully");
                        } else {
                            makeToast("data creation failed");

            } else {
                makeToast("Please check data entered");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download