Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to figure out how to do something with data returned from an AsyncTask.

I have an activity where I am calling an async Firebase get operation (operation existing in a different class), and I want to update an TextView existing in the Activity with the size of the ArrayList retrieved. Here is my Firebase call that get's called in Activity onCreate:

public void getAttendants() {

   ArrayList<AttendModel> attendees = new ArrayList<AttendModel>();
    FirebaseConnection.getInstance().getAllAttendeesFor(uuid, attendees);

    Log.d("attendees", String.valueOf(attendees.size()));
}

and here is my Firebase operation :

 public void getAllAttendeesFor(String UUID, final ArrayList<AttendModel> attendArray) {
    final DatabaseReference attendObjects = getDatabaseTableWith(Constants.tableAttendObject);

    Query queryRef = attendObjects.orderByChild(Constants.taAttendObjectUUID).equalTo(UUID);

    queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                HashMap<String, Object> attend = (HashMap<String, Object>) postSnapshot.getValue();
                String UUID = (String) attend.get(Constants.taAttendObjectUUID);
                String userUsername = (String) attend.get(Constants.AttendObjectUserUsername);

                AttendModel attendModel = new AttendModel(userUsername, UUID);
                attendArray.add(attendModel);

 //here would like to notify or somehow return the attendArray
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

}

What is the best approach of this in Android? Is there the possibility to implement an Adapter of sorts or a completion handler?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
706 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...