문제

I'm writing a simple xmpp client in android and I have a problem with update contactList. Im using a MatrixCursor with SimpleCursorAdapter to do it. When prog updates list it starts futureTask's thread. Data is ok, but list on screen doesn't refresh because (I think) this futureTask's thread is waiting for execute?

drawContactList method is called from one listener when any contact change status. When I copy call to main for example it works perfectly.

Any idea how to fix it?

Code:

static ListView contactList;
static MatrixCursor clCursor;
static SimpleCursorAdapter adapterList;

private final String[] matrixCols = new String[] { "_id", "username", "description", "icon" };
private final String[] menuCols = new String[] {"username", "description", "icon" };
private final int[] toWhatId = new int[] { R.id.clUsername, R.id.clDescription, R.id.clStatusIcon };

...
public void drawContactList(ArrayList<Contact> contacts, Context context) {

    clCursor = new MatrixCursor(matrixCols);

    startManagingCursor(clCursor);
    if(contacts != null){
        for (Contact contact : contacts) {          
            clCursor.addRow(new Object[] { contact.id, contact.name, contact.description, contact.icon });
        }
    }
    adapterList = new SimpleCursorAdapter(getApplicationContext(), R.layout.contactlist, clCursor, menuCols, toWhatId); 
    //in this line futureTask starts

    contactList.setAdapter(adapterList);
}
도움이 되었습니까?

해결책

I found a solution. Im using Handler to call this method. It works perfectly :)

private Handler contactListHandler = new Handler();

contactListHandler.post(new Runnable() {
   public void run() {
      System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
      drawContactList(xmppConnection.updateContacts(presence), context);
   }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top