Search in sources :

Example 1 with TeamMembersAdapter

use of ca.dal.cs.athletemonitor.athletemonitor.adapters.TeamMembersAdapter in project SEProject by NicholasBarreyre.

the class TeamDetailActivity method populateMemberList.

/**
 * Populates the list of teams associated with the user
 */
private void populateMemberList() {
    final ListView teamMemberListView = findViewById(R.id.memberList);
    // retrieve database reference to the team members
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference teamsReference = database.getReference("teams/" + team.getId() + "/teamMembers");
    teamMemberAdapter = new TeamMembersAdapter(this, new ArrayList<String>());
    teamsReference.addChildEventListener(new ChildEventListener() {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            teamMemberAdapter.add(dataSnapshot.getValue(String.class));
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
            teamMemberAdapter.remove(dataSnapshot.getValue(String.class));
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    teamMemberListView.setAdapter(teamMemberAdapter);
    teamMemberListView.setOnItemClickListener(new TeamDetailActivity.TeamMemberListClickListener());
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) ListView(android.widget.ListView) DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) ArrayList(java.util.ArrayList) TeamMembersAdapter(ca.dal.cs.athletemonitor.athletemonitor.adapters.TeamMembersAdapter) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Aggregations

ListView (android.widget.ListView)1 TeamMembersAdapter (ca.dal.cs.athletemonitor.athletemonitor.adapters.TeamMembersAdapter)1 ChildEventListener (com.google.firebase.database.ChildEventListener)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 DatabaseReference (com.google.firebase.database.DatabaseReference)1 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)1 ArrayList (java.util.ArrayList)1