-2

Hi I am trying to check whether recycler view current position has changed. and get that position while scrolling. Tried getting it inside onbind but it gets called only once. Searched for answers and found this. But looking for some workaround to implementing it. Let me know

@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {


    final News news = episodeList.get(position);
    Log.e(TAG, "onBindViewHolder: " + holder.getAdapterPosition() );
}

Above here all the positions are logged all together.

rishi95
  • 57
  • 2
  • 6
  • you know how bind view works dear ? please find it and i think it works like it creates view according the screen height , lets say you have 20 items and according to the device height it can only show 6 items , then it binds the view for 6 items , then when you scroll down or up , it will again bind views , According to you requirement i would prefer you to find the center item position among the current items in list – Quick learner Jun 14 '18 at 07:13
  • The current items are huge so in a screen at a single point their is only one item. but When I try to log the adapter position I am getting all the positions inside it @quicklearner – rishi95 Jun 14 '18 at 07:34
  • Can u post code here – Quick learner Jun 14 '18 at 07:35
  • i told u , that it will change position when you scroll list up or down ,did you try finding the center item and save its position when its completely invisible ? – Quick learner Jun 14 '18 at 09:45

1 Answers1

1

try this :

just use your own layout manager , because my recycler view scrolling horizontally

Save your X-Position as class variable and update each change within the onScrollListener. Ensure you don't reset overallXScroll (f.e. onScreenRotationChange)

private int overallXScroll = 0;
 //...
 mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);

        overallXScroll = overallXScroll + dx;
        Log.i("check","overall X  = " + overallXScroll);

    }
 });