我做了一个解析查询,现在我需要实现实时查询。但是我的查询有一个List<ParseObject>
,我可以看到在这个liveQuery
方法中它是不同的。
public void onEvent(ParseQuery<ParseObject> query, final ParseObject object) {
ParseQuery 就是这个方法所具有的——请参阅我以前的帖子)来查看。
这是文档中建议的代码:
if (parseLiveQueryClient != null) {
ParseQuery<ParseObject> parseQuery = new ParseQuery("Message");
parseQuery.whereEqualTo("destination", "pokelist");
SubscriptionHandling<ParseObject> subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);
subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new SubscriptionHandling.HandleEventCallback<ParseObject>() {
@Override
public void onEvent(ParseQuery<ParseObject> query, final ParseObject object) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
EditText pokeText = findViewById(R.id.pokeText);
numPokes++;
if(numPokes == 1) {
pokeText.setText("Poked " + numPokes + " time.");
}
else {
pokeText.setText("Poked " + numPokes + " times.");
}
}
});
}
});}
我做了这个并且确实更新了我的消息列表。有什么建议么?我是解析新手,很困惑!
ParseQuery<ParseObject> query = ParseQuery.getQuery("Conversaciones");
queryChat = ParseObject.createWithoutData("Chat", idChatSeleccionadoAppUsuario);
query.whereEqualTo("ChatId", queryChat);
query.include("Usuario");
query.include("ChatId");
SubscriptionHandling<ParseObject> subscriptionHandling= App.parseLiveQueryClient.subscribe(query);
subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new SubscriptionHandling.HandleEventCallback<ParseObject>() {
@Override
public void onEvent(final ParseQuery<ParseObject> query, final ParseObject object) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
listaDeMensajes.add(object);
}
});
mMessageAdapter = new MessageListAdapter(getContext(), listaDeMensajes);
mMessageRecycler.setAdapter(mMessageAdapter);
queryFromChat();
}
});