Home > Mobile >  When RecyclerView sliding flip up findFirstVisibleItemPosition why not () to obtain the value of the
When RecyclerView sliding flip up findFirstVisibleItemPosition why not () to obtain the value of the

Time:01-22


RecyclerView sliding up pages, linearLayoutManager. FindFirstVisibleItemPosition why not () to obtain the value of the change?

Slipping time is will change, such as from 1 to 9, slip up has been stuck in 9, (specifically: it jumped to 8, and then immediately into 9)

Please help me to look at: why this happens? Code:

The class PdfScrollListener extends RecyclerView. OnScrollListener {
Int currentPage=0;
Int lastPage=0;
PdfActivity PdfActivity;

Public PdfScrollListener PdfActivity (PDF) {
PdfActivity=PDF;
}

@ Override
Public void onScrollStateChanged (@ NonNull RecyclerView RecyclerView, int newState because) {
The e (" Position ", "============:" + linearLayoutManager. FindFirstVisibleItemPosition ());

LinearLayoutManager LinearLayoutManager=(LinearLayoutManager) recyclerView. GetLayoutManager ();
If (((LinearLayoutManager) recyclerView getLayoutManager ()). FindFirstVisibleItemPosition ()==1) {
CurrentPage=0;
} else {
CurrentPage=((LinearLayoutManager) recyclerView getLayoutManager ()). FindFirstVisibleItemPosition ();
}

//insert again after two pages

If (currentPage & gt; LastPage & amp; & CurrentPage + 2 & lt; PdfActivity. PageCount) {//judgment does not exceed the total number of pages in advance to insert two page
PdfActivity. GoDown (currentPage);
RecyclerView. GetAdapter (.) notifyItemInserted (currentPage + 2);
PdfActivity. DeletePage (currentPage);

}

If (currentPage & lt; LastPage & amp; & CurrentPage - 2 & gt;=0 & amp; & RecyclerView. GetAdapter (.) getItemId (currentPage - 2)==recyclerView. NO_ID) {
RecyclerView. GetAdapter (.) notifyItemInserted (currentPage - 3);
}
RecyclerView. Invalidate ();
LastPage=currentPage;

}

}

CodePudding user response:

Done, because recyclerView. GetAdapter () notifyItemInserted (currentPage - 3) and insert the item of

But I will not insert item, as long as it is ok to modify the data source, to use. NotifyDataSetChanged ()
  • Related