title: Add items to a List in Firebase in Android
body: <p>I am having a hard time trying to figure out how to add more items dynamically to a List in Firebase. As of now I am able to add just one item at the correct firebase location. The user needs to be able to add more items to the list. I am using a custom model class for the data. I would greatly appreciate any help, Thanks.</p>
  
  <pre><code> FloatingActionButton floatSave = (FloatingActionButton) rootView.findViewById(R.id.fabSave);
          floatSave.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  myFirebaseRef = new Firebase("https://you.firebaseio.com/");
                  myFirebaseRef = new Firebase("https://you.firebaseio.com/" + "/users/" + myFirebaseRef.getAuth().getUid());
                  String partyname = partyName.getText().toString();
                  String when = fromDateEtxt.getText().toString();
                  String timeOf = fromTimeEtxt.getText().toString();
                  String userItems1 = addThisItem.getText().toString();
                  userItems.add(userItems1);
                  Map&lt;String,Object&gt; values = new HashMap&lt;&gt;();
                  values.put("partyname", partyname);
                  values.put("When", when);
                  values.put("timeOf", timeOf);
                  values.put("userItems", userItems);
                  myFirebaseRef.push().setValue(values);
              }
          });
  </code></pre>
  
  <p>//Here is how I try to add additional items to the "userItems" List</p>
  
  <pre><code>final Button addItem = (Button) rootView.findViewById(R.id.buttonAddItem);
          addItem.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  SharedPreferences pref = getActivity().getSharedPreferences("MyPref", 0);
                  SharedPreferences.Editor editor = pref.edit();
  
                  String savedParty = pref.getString("thisPostKey", null);
                  myFirebaseRef = new Firebase("https://you.firebaseio.com/users/8d5d9915-54d8-4fc1-b92f-b45569e8089b/"+ savedParty + "/userItems");
  
                  String additem = addThisItem.getText().toString();
  
  
                  userItems.add(additem);
                  myFirebaseRef.push().setValue(additem);
                  System.out.println("There are " + thisKey + savedParty);
  
  
              }
          });
  
  public class PartyPost {
  
  private String partyname;
  private String timeOf;
  private String when;
  private List userItems;
  
  
  public PartyPost(String partyname, String timeOf, String when, List userItems) {
      // empty default constructor, necessary for Firebase to be able to deserialize blog posts
      this.partyname = partyname;
      this.timeOf = timeOf;
      this.when = when;
      this.userItems = userItems;
  }
  
  public void setPartyname(String partyname) {
      this.partyname = partyname;
  }
  
  public void setTimeOf(String timeOf) {
      this.timeOf = timeOf;
  }
  
  public void setWhen(String when) {
      this.when = when;
  }
  
  public void setUserItems(List&lt;String&gt; userItems) {
      this.userItems = userItems;
  }
  
  public String getPartyname() {
      return partyname;
  
  }
  public String getTimeOf() {
      return timeOf;
  }
  public String getWhen() {
      return when;
  }
  
  public List getUserItems() {
      return userItems;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code> {
   "users" : {
     "8d5d9915-54d8-4fc1-b92f-b45569e8089b" : {
       "-KDcHcfvc3CM-d8TWPE9" : {
        "When" : "2-2-2017",
        "partyname" : "Super Bowl",
        "timeOf" : "5:00PM",
        "userItems" : [ "Beer" ]
      },
       "-KDcHcjRbxXzCvRFa-No" : {
        "userItems" : {
        "-KDcLXIJ7I9TUFEDyyrA" : "Chips"
       }
     }
  }
  </code></pre>
  
  <p>}
  }</p>