I am doing an Android App. I have been successful in writing to Firebase, I however am having a problem reading from Firebase into a ListView. If anyone can assist in getting th
You can use the Firebase UI library.
Just add the dependency:
dependencies {
// FirebaseUI Database only
compile 'com.firebaseui:firebase-ui-database:1.0.1'
}
Then define a simple class to map your object:
public class MyObject {
private String name;
private String address;
private String dateTime;
public MyObject() {
}
....
}
Then just use something like:
mRef = new Firebase("https://saica-sgb-77a4f.firebaseio.com/Meetings");
mListView = (ListView) findViewById(R.id.ListView);
mAdapter = new FirebaseListAdapter<MyObject>(this, MyObject.class, R.layout.myLayout, mRef) {
@Override
protected void populateView(View view, MyObject myObj, int position) {
//Set the value for the views
((TextView)view.findViewById(R.id.xxx)).setText(myObj.getName());
//...
}
};
mListView.setAdapter(mAdapter);
Use ChildEventListener and put your this code:
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String(this,android.R.layout.simple_list_item_1, mMeetings);
mListView.setAdapter(arrayAdapter);
inside the onChildAdded....
Also creat Model class to get data from firebase
public class User {public String name;public String date;public String time;// Default constructor required for calls to // DataSnapshot.getValue(User.class)
public User() {}public User(String name, String time, String date) {this.name = name;
this.time= time;this.date=date;}
thanks it will help you..