ParseLiveQuery 更新列表
ParseLiveQuery updating a list
您好,我正在尝试实时更新列表以创建聊天应用程序。
目前我正在尝试用这种方法查询...
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);
}
});
}
});
}
我需要的是更新 List<ParseObject> listaDeMensajes
,就像 findInBackground 方法将拥有 List 一样。
这个问题的答案正如 Davi Macedo 所说。我所做的是根据需要自定义查询。然后在 运行 方法中更新列表!.
listaDeMensajes.add(object);
mMessageAdapter.notifyDataSetChanged();
mMessageRecycler.scrollToPosition(0);
您好,我正在尝试实时更新列表以创建聊天应用程序。 目前我正在尝试用这种方法查询...
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);
}
});
}
});
}
我需要的是更新 List<ParseObject> listaDeMensajes
,就像 findInBackground 方法将拥有 List 一样。
这个问题的答案正如 Davi Macedo 所说。我所做的是根据需要自定义查询。然后在 运行 方法中更新列表!.
listaDeMensajes.add(object);
mMessageAdapter.notifyDataSetChanged();
mMessageRecycler.scrollToPosition(0);