简体   繁体   中英

How to load data into RecyclerView while scrolling

I am using RecyclerView, and its calling all the data items, which are not even seen by user. So how can i load only that item which are seen by user, or load while scrolling

XML:

  <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/post_ImagesRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_margin="5dp"
    android:background="@color/grey_bg"
    android:nestedScrollingEnabled="false"/>

Java:

    postAdapter = new PostAdapter(context, false, false, postList, this, 1, loadType);
        LinearLayoutManager postListManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        post.setLayoutManager(postListManager);
        post.setAdapter(postAdapter);

As it's said in official documentation,

The views in the list are represented by view holder objects. These objects are instances of a class you define by extending RecyclerView.ViewHolder. Each view holder is in charge of displaying a single item with a view. For example, if your list shows music collection, each view holder might represent a single album. The RecyclerView creates only as many view holders as are needed to display the on-screen portion of the dynamic content, plus a few extra. As the user scrolls through the list, the RecyclerView takes the off-screen views and rebinds them to the data which is scrolling onto the screen.

So, if you use RecyclerView you shouldn't worry about this problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM