ParseLiveQuery更新列表

时间:2019-09-17 16:57:38

标签: android parse-platform parse-android-sdk

您好,我正在尝试实时创建列表,以创建聊天应用程序。 目前,我正在尝试使用此方法进行查询...

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);
                        }
                    });
                }
            });
}

我需要像对findInBackground方法使用List一样,更新List<ParseObject> listaDeMensajes

1 个答案:

答案 0 :(得分:0)

答案就如Davi Macedo所说。我所做的就是根据需要自定义查询。然后在run方法中更新列表!。

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