我想使用setskip方法实现Pagination,我正在使用recyclerview并且想要在用户滚动时加载更多项目,我不想使用ParseUeryAdapter所以有什么办法让我可以使用setskip方法做到这一点,因为我我是android的新手,所以请建议我任何帮助或解决方案。
public class MainActivity extends AppCompatActivity {
VideoAdapter videoAdapter;
private int previousTotal = 0;
private boolean loading = true;
private int visibleThreshold = 5;
int firstVisibleItem, visibleItemCount, totalItemCount;
int limit=0;
boolean loadmore=false;
ArrayList<Video> testParseModels=new ArrayList<>();
RecyclerView recyclerView;
LinearLayoutManager linearLayoutManager;
ParseQuery<ParseObject> parseQuery;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
Parse.initialize(new
dataParse();
/*parseQuery.setLimit(recyclerView.getChildCount()+5);
if(recyclerView.getChildCount()>5){
parseQuery.setSkip(5);
}*/
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(loadmore==true){
parseQuery.setSkip(limit);
parseQuery.setLimit(5);
}else{
parseQuery.setLimit(5);
}
dataParse();
}
});
videoAdapter = new VideoAdapter(testParseModels, MainActivity.this);
linearLayoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(videoAdapter);
/*if(loadmore==true)
{
parseQuery.setSkip(limit);
parseQuery.setLimit(5);
}
else
{
parseQuery.setLimit(5);
}*/
}
public void dataParse(){
parseQuery=ParseQuery.getQuery("Video");
parseQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
/* limit = limit+ objects.size();
if(objects.size()==0)
{
loadmore = false;
}
else
{
loadmore = true;
}*/
if (e == null) {
for (int i = 0; i < objects.size(); i++) {
Video video = new Video();
video.setCityname(objects.get(i).getString("cityname"));
video.setName(objects.get(i).getString("name"));
video.setStorageId(objects.get(i).getString("storageId"));
video.setS3link(objects.get(i).getString("s3link"));
//Log.d("s3link", objects.get(i).getString("cityname"));
testParseModels.add(video);
}
} else {
Toast.makeText(getApplicationContext(), "some error", Toast.LENGTH_LONG).show();
}
// videoAdapter.notifyDataSetChanged();
}
});
}
}