ParseLiveQuery 的问题
Problems with the ParseLiveQuery
我做了一个解析查询,现在我需要实现实时查询。但是我的查询有一个 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();
}
});
我解决了我的问题,就是这样...
先这样订阅
private void changeChatLive(){
listaDeMensajes.clear();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Conversaciones");
// Connect to Parse server
SubscriptionHandling<ParseObject> subscriptionHandling = parseLiveQueryClient.subscribe(query);
// 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);
}
});
}
});
}
然后我调用了这里的方法,瞧瞧 liveChat 运行。 NOTE:Call 您需要实时查询更新的方法!
queryConversaciones();
mMessageAdapter.notifyDataSetChanged();
**changeChatLive();**
我做了一个解析查询,现在我需要实现实时查询。但是我的查询有一个 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();
}
});
我解决了我的问题,就是这样...
先这样订阅
private void changeChatLive(){
listaDeMensajes.clear();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Conversaciones");
// Connect to Parse server
SubscriptionHandling<ParseObject> subscriptionHandling = parseLiveQueryClient.subscribe(query);
// 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);
}
});
}
});
}
然后我调用了这里的方法,瞧瞧 liveChat 运行。 NOTE:Call 您需要实时查询更新的方法!
queryConversaciones();
mMessageAdapter.notifyDataSetChanged();
**changeChatLive();**