0

我想使用 setskip 方法实现分页。我正在使用回收视图并希望在用户滚动时加载更多项目。我不想使用 ParseUeryAdapter 所以无论如何我可以使用 setskip 方法来做到这一点?

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();

        }
    });
}
}
4

0 回答 0