androidparse-platformparse-android-sdk

ParseLiveQuery updating a list


Hello at the moment I am trying to update a list in real-time creating a chat app. At the moment I am trying to query with this method ...

private void changeChatLive(String chat) {
    listaDeMensajes.clear();
    ParseQuery<ParseObject> parseQuery = new ParseQuery("Conversaciones");
    // This query can even be more granular (i.e. only refresh if the entry was added by some other user)
    // parseQuery.whereNotEqualTo(USER_ID_KEY, ParseUser.getCurrentUser().getObjectId());
    //ParseObject chatId = ParseObject.createWithoutData("Chat", chat);
     parseQuery.whereEqualTo("ChatId", chatId);
    // Connect to Parse server
    parseQuery.include("ChatId");
    SubscriptionHandling<ParseObject> subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);

    // Listen for CREATE events
    subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new
            SubscriptionHandling.HandleEventCallback<ParseObject>() {
                @Override
                public void onEvent(ParseQuery<ParseObject> query, ParseObject object) {

                    Handler handler = new Handler(Looper.getMainLooper());
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            mMessageAdapter.notifyDataSetChanged();
                            mMessageRecycler.scrollToPosition(0);
                            scroll.fullScroll(FOCUS_DOWN);
                        }
                    });
                }
            });
}

What I need is to update the List<ParseObject> listaDeMensajes as the same way that findInBackground method is going to have List.


Solution

  • The answer to this is as Davi Macedo said. What I did is to custom the query as you like. Then update the list in the run method!.

    listaDeMensajes.add(object);
    mMessageAdapter.notifyDataSetChanged();
    mMessageRecycler.scrollToPosition(0);