-2

I noticed that every time I scroll up/down my RecyclerView, the "onBindViewHolder" is being called and my data (Textviews and Imageviews) is being refreshed/reloaded in the background.

Is there a way I can tell the RecylerView to not refresh or reload, upon scrolling, a specific textview for example? Is there a method I need to override or something?

Aboodnet
  • 143
  • 15
  • recyclerview show items you should to see, if you can see 10 items in your screen and have 100 items in data list, recyclerview not bind all items and only bind items you can see, – Farrokh Oct 02 '18 at 05:28
  • 1
    It is called RecyclerView for that reason if you want it to not recycle use a listview. – Mohammad Tabbara Oct 02 '18 at 05:36
  • can you try putting viewHolder.setIsRecyclable(false); in your onBindViewHolder method. maybe it will do the work for you – Ashik Oct 02 '18 at 05:37
  • @Mohammad Tabbara, i guess you are right – Aboodnet Oct 02 '18 at 10:53

4 Answers4

1

Use SrcollDisabled RecyclerView

public class ScrollDisabledRecyclerView extends RecyclerView {
    public ScrollDisabledRecyclerView(Context context) {
        super(context);
    }

    public ScrollDisabledRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ScrollDisabledRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent e) {
        return false;
    }
}

Use it inside xml like this

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 <com....ScrollDisabledRecyclerView
                            android:id="@+id/recyclerView"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
0

RecyclerView only creates as many as view it needs to full fill the screen, and as its name says, it recycle or reuse the views it created by calling the onBindViewHolder, so that behavior is pretty normal.

If you need an specific position not to be recycled, take a look at this question.

Mosius
  • 1,602
  • 23
  • 32
0

I ended up achieving my goal by implementing some logic to check and control if values exist upon scrolling. I couldn't find other straight forward ways because as @Mohammad Tabbara said, this is how RecyclerView works by design.

Aboodnet
  • 143
  • 15
-1

Try this

yourAdapter adapter = new yourAdapter( , , );
adapter.notifyDataSetChanged();