firebase Populating a ListView


Assuming you have already set up an app in Android Studio, add a ListView to a layout (or skip if that's already done):

<?xml version="1.0" encoding="utf-8"?>

<!-- Your toolbar, etc -->

    android:layout_height="wrap_content" />


Now let's create a model for the data we're going to populate our ListView with:

public class Person {

    private String name

    public Person() {
        // Constructor required for Firebase Database

    public String getName() {
        return name;


Make sure your ListView has an id, then create a reference to it in your Activity and set its adapter to a new FirebaseListAdapter:

public class MainActivity extends AppCompatActivity {

    // ...

    private ListView mListView;

    protected void onCreate(Bundle savedInstanceState) {
        // Find the ListView
        mListView = (ListView) findViewById(;
         * Create a DatabaseReference to the data; works with standard DatabaseReference methods
         * like limitToLast() and etc.
        DatabaseReference peopleReference = FirebaseDatabase.getInstance().getReference()

        // Now set the adapter with a given layout
        mListView.setAdapter(new FirebaseListAdapter<Person>(this, Person.class,
                android.R.layout.one_line_list_item, peopleReference) {

            // Populate view as needed
            protected void populateView(View view, Person person, int position) {
                ((TextView) view.findViewById(;

After you've done that, add some data to your database and watch the ListView populate itself.