Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load all items in android RecyclerView at once

I'm too tired for searched this question in two day's , but i got false answer , I implement RecyclerView and it worked well, but my RecycleView have many items like photo's and video's like Instagram . it mean my adapter will invoke onBindViewHolder for all items to start download and loading image's and video's . but RecycleView just invoked onBindViewHolder for each item's when item is visible (scroll show it) . it's impossible ? if not how instagram can do that . pay attention : i don't want to using database for save image's and video's

 @Override
public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {

    Log.e("position",position+" ");

    thread t = new Thread(new Runnable(){
       public void run(){
           Bitmap bitmap = downloadPhoto();//it mean photo downloaded and converted to Bitmap
           runOnUiThread(new Runnable(){
               holder.imageView.setImageBitmap(bitmap);
           ));
       }

    });
    t.start();

}
like image 310
MrNadimi Avatar asked Jan 29 '23 05:01

MrNadimi


2 Answers

You can try embedding the recyclerview inside nested scroll view and do not forget to disable nested scrollview of recyclerview. This way all items will be loaded at once even though it violates the purpose of the recyclerview.

like image 70
Harjinder Bains Avatar answered Jan 31 '23 18:01

Harjinder Bains


Although I wouldn't recommend you to use this "solution", since it destroys the original purpose of using a RecyclerView, it is possible to let the RecyclerView invoke onBindViewHolder for every item at once. For it to work, just set the RecyclerView inside a NestedScrollView.

like image 36
Philipp Poropat Avatar answered Jan 31 '23 19:01

Philipp Poropat