0

I want to implement Pagination using setskip method, i am using recyclerview and want to load more items when user scrolls , i do not want to use ParseUeryAdapter so is there any way so that i can do this using setskip method, as i am new in android so please suggest me any help or solution.

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

        }
    });
}
}
Manuel
  • 14,274
  • 6
  • 57
  • 130
sandeep
  • 43
  • 1
  • 1
  • 10
  • 1
    Your question is not clear in your post. – Sneha Sarkar May 24 '17 at 07:03
  • Sneha, i want to display images from server using Picasso and in FeedVideos Model there is Thumbnails class in which there is getLink() method present , i want to fetch from this method – sandeep May 24 '17 at 07:05
  • This is a link for MOdel Class https://www.dropbox.com/s/8kg381q9vgmmfyo/FeedVideos.java?dl=0 – sandeep May 24 '17 at 07:14
  • what does `list.get(3).getLink()` prints in log ? – Somesh Kumar May 24 '17 at 09:11
  • let me check Somesh. – sandeep May 24 '17 at 09:13
  • Somesh, when i am trying to access any of element of Thumnails class like width or getLink then it throws nullpointer exception apart from that everything is fine please help me. – sandeep May 24 '17 at 09:19
  • Firstly, pass context of the Current Activity .. And also it throws null pointer exception only if it doesn't getting a valid url or there is not any image on the url provided .. – Hobbit May 24 '17 at 09:23
  • Umer, I am passing the context of imageview in Picaso also url are valid. can you please help me . Actually when i am trying to access any of element of Thumbnails class like width or getLink then it throws nullpointer exception apart from that everything is fine. Alos check my model class – sandeep May 24 '17 at 09:25
  • Share your code where you think problem exists??? – Hobbit May 24 '17 at 09:29
  • Make sure you have set values in Thumbnails before accessing that ?? Nothing is wrong with your thumbnail class, that only contains mutators and attributes .. – Hobbit May 24 '17 at 09:31
  • Problem occurred in Picasso.with(videoVH.webView.getContext()).load(result.getThumbnails().get(0).getLink()).placeholder(R.drawable.ic_food).error(R.drawable.ic_food).fit().noFade().into(videoVH.webView); – sandeep May 24 '17 at 09:33
  • can you post the specific json object of list position 3 ? which you're trying to access.. if you want you can replace all its value with dummy values – Somesh Kumar May 24 '17 at 09:34
  • Somesh, when i put dummy values then its working , can u suggest me what should i do and i have put the url of image – sandeep May 24 '17 at 09:39
  • Umer, what does it mean --Make sure you have set values in Thumbnails before accessing that ?? can u help me with the code – sandeep May 24 '17 at 09:40
  • Umer have u checked my code. – sandeep May 24 '17 at 09:56
  • Umesh can you please help me with the code...here i am attaching the link first is for code and second is for adapter https://www.dropbox.com/s/36lthk6l59xve0k/Fragment_Feed.java?dl=0 https://www.dropbox.com/s/89wqtbmzit2h3v9/PaginationAdapter.java?dl=0 please see this and do correct me – sandeep May 25 '17 at 07:27
  • Somesh, can you please help me i have shared those two link please help me on that – sandeep May 25 '17 at 07:28
  • Umer, what does it mean --Make sure you have set values in Thumbnails before accessing that ?? can u help me with the code – sandeep May 28 '17 at 11:39
  • please help me , i think i m wrong with that point how i will set values in thumbnails – sandeep May 28 '17 at 11:40

0 Answers0