gpt4 book ai didi

Android ParseQueryAdapter 总是空的

转载 作者:行者123 更新时间:2023-11-30 02:36:10 27 4
gpt4 key购买 nike

我正在尝试从 Parse.com 获取数据,并按照其网站上的说明和示例进行操作,但我遇到了似乎无法解决的问题。请求的查询始终为空。我使用以下代码

public void createParseQuery(final int markerId){
ParseQueryAdapter.QueryFactory<CommentPost> queryAdapterFactory =
new ParseQueryAdapter.QueryFactory<CommentPost>() {
public ParseQuery<CommentPost> create() {
ParseQuery<CommentPost> parseQuery = CommentPost.getQuery();
parseQuery.whereEqualTo("markerId", markerId);
parseQuery.include("comment"); //comment define
parseQuery.include("rating");
return parseQuery;
}
};
queryAdapter = new ParseQueryAdapter<CommentPost>(this, queryAdapterFactory) {
@Override
public View getItemView(CommentPost post, View view, ViewGroup viewGroup){
if (view == null) {
view = View.inflate(getContext(), R.layout.item_comment_post, null);
}
TextView textViewPostUsername = (TextView) view.findViewById(R.id.textViewPostUsername);
TextView textViewPostComment = (TextView) view.findViewById(R.id.textViewPostComment);
RatingBar ratingBarPostRating = (RatingBar) view.findViewById(R.id.ratingBarPostRating);
textViewPostUsername.setText(post.getUser().getUsername());
textViewPostComment.setText(post.getComment());
ratingBarPostRating.setProgress(post.getRating());
return view;
}
};
Boolean adapterEmpty= queryAdapter.isEmpty();
Log.i("DEBUG","Adapter is empty "+adapterEmpty);
ListView lv = (ListView)findViewById(R.id.listView111);
lv.setAdapter(queryAdapter);
}

此处 adapterEmpty 始终返回“true”,并且 listView 未更新。

CommentPost类:

@ParseClassName("data")
public class CommentPost extends ParseObject {
ParseUser user;
int markerId;
String comment;
int rating;
public CommentPost() {
super();
}
public String getComment() {
return getString("comment");
}
public ParseUser getUser() {
return getParseUser("user");
}
public int getRating() {
return getInt("rating");
}
public void setComment(ParseUser user, int markerId, String comment,
int rating) {
put("user", user);
put("markerId", markerId);
put("comment", comment);
put("rating", rating);
}
public static ParseQuery<CommentPost> getQuery() {
return ParseQuery.getQuery(CommentPost.class);
}
}

当我执行此代码时(来自 Parse 网站上的教程):

mainAdapter = new ParseQueryAdapter<ParseObject>(this, "data");
mainAdapter.setTextKey("comment");

ListView lv = (ListView)findViewById(R.id.listView111);
lv.setAdapter(mainAdapter);

它工作正常,我正在获取类“数据”的所有已保存评论,但我需要自定义查询。任何帮助将不胜感激:)

最佳答案

开始工作了。这是代码:

public void createParseQuery(final int markerId) {

ParseQueryAdapter.QueryFactory<CommentPost> queryAdapterFactory =
new ParseQueryAdapter.QueryFactory<CommentPost>() {
public ParseQuery<CommentPost> create() {
ParseQuery<CommentPost> parseQuery = CommentPost.getQuery();
parseQuery.whereEqualTo("markerId", markerId);
parseQuery.include("user");
parseQuery.orderByDescending("createdAt");

return parseQuery;
}
};

queryAdapter = new ParseQueryAdapter<CommentPost>(this, queryAdapterFactory) {
@Override
public View getItemView(CommentPost post, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(getContext(),
R.layout.item_comment_post, null);
}
TextView textViewPostUsername = (TextView) view
.findViewById(R.id.textViewPostUsername);
TextView textViewPostComment = (TextView) view
.findViewById(R.id.textViewPostComment);
RatingBar ratingBarPostRating = (RatingBar) view
.findViewById(R.id.ratingBarPostRating);

textViewPostUsername.setText(post.getUser().getUsername());
textViewPostComment.setText(post.getComment());
ratingBarPostRating.setProgress(post.getRating());
return view;
}
};

关于Android ParseQueryAdapter 总是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26492511/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com