Nebneb
Nebneb

Reputation: 114

Android Parse.com Chat with parseQueryAdapter does not refresh

I'm trying to add a chat feature in my Android app using Parse.com. I'm using a custom parseQueryAdapter. Problem is that when I send a message or when I receive a new message, my adapter does not update. I tried to add both

adapter.notifyDataSetInvalidated();
adapter.clear();
adapter.loadObjects();
adapter.notifyDataSetChanged();

in done callback and even in a dedicated refresh button.

This is how it works :

Each time, the listView displays same messages, and I have to come back to the previous fragment and re-open the chat fragment to see new messages...

I noticed that the getCount() method always return what is displayed.

Any idea of how I could refresh my listView's data ?

Thanks !

Upvotes: 2

Views: 464

Answers (2)

Nebneb
Nebneb

Reputation: 114

Here are few more explanations The problem came from the adapter lifecycle. I had :

constructor {
  set up the messages list
  set this list as source of data in query
  ...
}

when I tried to refresh, data were updated, but the list is still the same, so I got the same result ! As it is not possible to change the query of a existing parseQueryAdapter, I completely changed the way I get messages, with a conversation pointer in my parse object. Now it is just a simple parse query adapter:

ParseQuery<ParseObject> q = new ParseQuery<ParseObject>("Message");
q.whereEqualTo("conversationPointer", parseConversationId);

Upvotes: 0

Nebneb
Nebneb

Reputation: 114

The problem was that I get the list of message in a conversation in the constructor of the parseQueryAdapter and then return the query. The parseQueryAdapter works well, displaying me the result of the query. If I send a message in a conversation, it has no effect on the list made in the constructor...

So I added a column in my message ParseObject, and do a simple whereEqualTo() to have the right messages. It works perfectly now !

Upvotes: 0

Related Questions