Pooveshin Pooveshin - 5 months ago 29
Android Question

Write multiple items to firebase in Android

I've written an android app using Firebase as the backend. My problem is only one item can be stored in Firebase and when I try to write more data it replaces the existing data. I want to write multiple bits and data and retrieve them in a list view or something.

My Code is below:

public class Capture_Meetings extends AppCompatActivity {

private EditText editTextName;
private EditText editTextAddress;
private EditText editDateTime;
private TextView textViewPersons;
private Button buttonSave;

protected void onCreate(Bundle savedInstanceState) {


buttonSave = (Button) findViewById(R.id.buttonSave);
editTextName = (EditText) findViewById(R.id.editTextName);
editTextAddress = (EditText) findViewById(R.id.editTextAddress);
editDateTime = (EditText) findViewById(R.id.editDateTime);

textViewPersons = (TextView) findViewById(R.id.textViewPersons);

buttonSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Creating firebase object
Firebase ref = new Firebase(Config.FIREBASE_URL);

//Getting values to store
String name = editTextName.getText().toString().trim();
String address = editTextAddress.getText().toString().trim();
String DateTime = editDateTime.getText().toString().trim();

//Creating Person object
final MeetingUser person = new MeetingUser();

//Adding values

//Storing values to firebase

//Value event listener for realtime data update
ref.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot snapshot)
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
//Getting the data from snapshot
MeetingUser person = postSnapshot.getValue(MeetingUser.class);

//Adding it to a string
String string = "\n Name of School: "+person.getName()+"\n Date:"+ person.getDateTime()+"\nMeeting Notes: "+person.getAddress()+"\n\n";

//Displaying it on textview

public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());



Have a look at the Firebase documentation. You can use the push method to append data to a node, which will have a unique id.