I’m trying to Dynamically update a Friends list using the Asmack API. For testing purposes I am using my Facebook account. I found that if I login with my connection then use
adapter = new ArrayAdapter<Contact>(this, android.R.layout.simple_list_item_1, contacts);
listView.setAdapter(adapter);
Roster people = connection.getRoster();
people.people.addRosterListener(new RosterListener() {
public void presenceChanged(Presence arg0) {
contacts.clear();
for(RosterEntry entry: people.getEntries()) {
if(people.getPresence(entry.getUser()).equals(Presence.Type.available)) {
Contact person = new Contact();
person.setJid(entry.getUser());
person.setName(entry.getName());
contacts.add(person);
}
}
adapter.notifyDataSetChanged();
}
This doesn’t seem to work. My listView still remains empty. Any thoughts?
Thanks in advance,
Mike
For anyone curious the best way to do it was using an AsyncTask. To populate it initially and a RosterListener to keep it up to date. As real time changes occurred.
Here is my code. Hopefully it helps someone in the future.