android - findLastCompletelyVisibleItemPosition() method of recylerview not working for variable size item -
i used following code
private boolean islastitemdisplaying(recyclerview recyclerview){ if (recyclerview.getadapter().getitemcount() != 0) { int lastvisibleitemposition = ((linearlayoutmanager) recyclerview.getlayoutmanager()).findlastcompletelyvisibleitemposition(); if (lastvisibleitemposition != recyclerview.no_position && lastvisibleitemposition == recyclerview.getadapter().getitemcount() - 1) return true; } return false; } private final recyclerview.onscrolllistener onscrolllistener = new recyclerview.onscrolllistener() { @override public void onscrollstatechanged(final recyclerview recyclerview, final int newstate) { // code if (islastitemdisplaying(recyclerview)) { if (loadallow){ if (postproviderlist.size()<20 && postproviderlist.size()>=1) { loadallow = false; }else{ loadallow = false; loadpostsmore(); } } } } @override public void onscrolled(final recyclerview recyclerview, final int dx, final int dy) { // code } };
to detect last item visible in recyclerview list , load more items. had been working untill had items of different heights , single item taking height equal of phone screen. islastitemdisplaying(recyclerview recyclerview)
returning false when last item visible. sure there better solution.
issue resolved might face same problem. problem findlastcompletelyvisibleitemposition()
method. since item size of last visible item more device screen, method returning false. should replaced findlastvisibleitemposition()
. works expected.
so can remove last item if want using code :
adapter.postproviderlist.remove(postproviderlist.size()); adapter.notifyitemremoved(postproviderlist.size());
hope helps :)
Comments
Post a Comment