title: Firebase push data on same child using Hashmap
body: <p>For my android application i'm trying to add multiple strings to the same child (Firebase Unique ID) in which the user will enter on different layouts. I'm using a Hashmap to put the strings into Firebase. I have 4-5 different layouts that the user would come across and needs to fill out the information, but when I save it in the Database, it always goes under a different Unique ID and I need it all to be under the same one.</p>
  
  <p><a href="https://i.stack.imgur.com/PYmv2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PYmv2.png" alt="In the image I need all the information to be under just the first unique ID."></a> </p>
  
  <p>Here's my code, I created a Parent class with every layout (the other classes) having some method to access the Hashmap. </p>
  
  <p>Parent Class:</p>
  
  <pre><code>public class FireBaseDataMap {
  
      private HashMap&lt;String, String&gt; dataMap = new HashMap&lt;String, String&gt;();
  
      public HashMap&lt;String, String&gt; fireebaseMap(){
          return dataMap;
      }
  
  }
  </code></pre>
  
  <p>First Activity: I put an arrow where I needed help in the onClick(View view) method.</p>
  
  <pre><code>    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
      //UI References
      private EditText firstName;
      private EditText lastName;
      private EditText birthPlace;
      private EditText etxtBirthdate;
      private EditText etxtMissingDate;
      private Button saveButton;
      private Button cancel_button;
  
  
      private DatePickerDialog birthdateDatePickerDialog;
      private DatePickerDialog missingDatePickerDialog;
  
      private DatabaseReference mDatabase;
  
      private SimpleDateFormat dateFormatter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
  
          findViewsById();
  
          setDateTimeField();
  
          saveButton = (Button) findViewById(R.id.saveButton);
          cancel_button = (Button) findViewById(R.id.cancel_button);
  
          saveButton.setOnClickListener(this);
          cancel_button.setOnClickListener(this);
  
      }
  
      private void findViewsById() {
  
          firstName = (EditText) findViewById(R.id.firstName);
          lastName = (EditText) findViewById(R.id.lastName);
          birthPlace = (EditText) findViewById(R.id.birthPlace);
  
  
          etxtBirthdate = (EditText) findViewById(R.id.etxt_birthdate);
          etxtBirthdate.setInputType(InputType.TYPE_NULL);
          etxtBirthdate.requestFocus();
  
  
          etxtMissingDate = (EditText) findViewById(R.id.etxt_missingdate);
          etxtMissingDate.setInputType(InputType.TYPE_NULL);
          etxtMissingDate.requestFocus();
  
  
      }
  
      @Override
      public void onClick(View view) {
          if(view == etxtBirthdate) {
              birthdateDatePickerDialog.show();
          }
  
          if(view == etxtMissingDate){
              missingDatePickerDialog.show();
          }
          if(view == saveButton){
  
              String FirstName = firstName.getText().toString().trim();
              String LastName = lastName.getText().toString().trim();
              String BirthPlace = birthPlace.getText().toString().trim();
              String BirthDate = etxtBirthdate.getText().toString().trim();
              String MissingDate = etxtMissingDate.getText().toString().trim();
  
              mDatabase = FirebaseDatabase.getInstance().getReference();
  
              // Here is where im accessing the parent class and need help &lt;------
              FireBaseDataMap obj = new FireBaseDataMap();
              HashMap&lt;String, String&gt; dataMap = obj.fireebaseMap();
  
              if(FirstName.isEmpty()) {
                  FirstName = "n/a";
                  dataMap.put("firstName", FirstName);
              }
              else
                  dataMap.put("firstName", FirstName);
  
              if(LastName.isEmpty()) {
                  LastName = "n/a";
                  dataMap.put("lastName", LastName);
              }
  
              else
                  dataMap.put("lastName", LastName);
  
              if(BirthPlace.isEmpty()) {
                  BirthPlace = "n/a";
                  dataMap.put("birthPlace", BirthPlace);
              }
  
              else
                  dataMap.put("birthPlace", BirthPlace);
  
              if(BirthDate.isEmpty()) {
                  BirthDate = "n/a";
                  dataMap.put("birthDate", BirthDate);
              }
  
              else
                  dataMap.put("birthDate", BirthDate);
  
              if(MissingDate.isEmpty()) {
                  MissingDate = "n/a";
                  dataMap.put("missingDate", MissingDate);
              }
  
              else
                  dataMap.put("missingDate", MissingDate);
  
  
              mDatabase.child("null").push().setValue(dataMap);
  
          }
  
          if(view == cancel_button){
              startActivity(new Intent(this, PhysicalAttributes.class));
  
          }
      }
  
  }
  </code></pre>
  
  <p>Second Activity: I'm just posting the method where I need help on for this activity so it wont seem so long, but if need the full class to understand then I can update it.</p>
  
  <pre><code> public void onClick(View view) {
  
  
  
          if (view == saveButton) {
  
  
              String PersonAge = personAge.getText().toString().trim();
              String PersonHeight = personHeight.getText().toString().trim();
              String PersonWeight = personWeight.getText().toString().trim();
  
              mDatabase = FirebaseDatabase.getInstance().getReference();
  
              FireBaseDataMap obj = new FireBaseDataMap();
              HashMap&lt;String, String&gt; dataMap = obj.fireebaseMap();
  
  
              if(PersonAge.isEmpty()){
                  PersonAge = "n/a";
                  dataMap.put("personAge", PersonAge);
              }
  
              else
                  dataMap.put("personAge", PersonAge);
  
              if(PersonHeight.isEmpty()) {
                  PersonHeight = "n/a";
                  dataMap.put("personHeight", PersonHeight);
              }
              else
                  dataMap.put("personHeight", PersonHeight);
  
              if(PersonWeight.isEmpty()) {
                  PersonWeight = "n/a";
                  dataMap.put("personWeight", PersonWeight);
              }
              else
                  dataMap.put("personWeight", PersonWeight);
  
              mDatabase.child("null").push().setValue(dataMap);
  
  
          }
          if (view == cancel_button) {
  
  
          }
  
      }
  }
  </code></pre>
  
  <p>I've tried looking all over and tried different ways to make it work, but nothing. Any help would be appreciated. If clarification is needed then will try my best. </p>
  
  <p>Another way I was thinking of is if I can access the same saveButton on every activity if that'll work. </p>