我一直在試圖尋求各種其他問題的幫助,但我似乎無法找到解決方案。使用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