我一直在试图寻求各种其他问题的帮助,但我似乎无法找到解决方案。使用Parse和RecyclerView分页
OnScrollListener我使用:https://gist.github.com/ssinss/e06f12ef66c51252563e
rvHome.addOnScrollListener(new MainRecyclerViewScrollListener(linearLayoutManager) { @Override public void onLoadMore(int page) { fetchPosts(page); } });
public void fetchOfflinePosts() {
offlineListPosts = db.getAllPosts();
for (Post post : offlineListPosts) {
listPosts.add(post);
}
postAdapter.notifyDataSetChanged();
}
public void loadPosts() {
if (ConnectivityHelper.isConnected(getContext())) {
db.deleteAllPosts();
listPosts.clear();
fetchPosts(0);
} else {
swipeRefreshLayout.setRefreshing(false);
}
}
public void fetchPosts(int skip) {
ParseQuery<ParseObject> findPostsRequest = new ParseQuery<>("Post");
findPostsRequest.setSkip(skip);
findPostsRequest.orderByDescending("createdAt");
findPostsRequest.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> posts, ParseException e) {
if (e == null) {
for (ParseObject _post : posts) {
final Post post = new Post();
String objectId = _post.getObjectId();
String username;
String imageUrl;
if (_post.getString("username") != null) {
username = _post.getString("username");
} else {
username = "";
}
ParseQuery<ParseUser> findProfilePicQuery = ParseUser.getQuery();
findProfilePicQuery.whereEqualTo("username", username);
findProfilePicQuery.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> users, ParseException e) {
if (e == null) {
for (ParseUser user : users) {
if (user.getParseFile("profilePic") != null) {
post.setProfilePicUrl(user.getParseFile("profilePic").getUrl());
} else {
post.setProfilePicUrl("");
}
}
}
}
});
if (_post.getParseFile("photo") != null) {
imageUrl = _post.getParseFile("photo").getUrl();
} else {
imageUrl = "";
}
post.setObjectId(objectId);
post.setUsername(username);
post.setImageUrl(imageUrl);
db.addPost(post);
}
fetchOfflinePosts();
swipeRefreshLayout.setRefreshing(false);
}
}
});
}
通过使用上面的代码,我可以得到RecyclerView一旦到达最后一个项目,以装载更多的物品,但该职位获取是一样的那些我已经得到了。我知道我得到了一些非常简单的错误。任何帮助将非常感激。
感谢。我现在就试试看。 –
如果您有关于实施的问题,我们可以讨论。 – savepopulation