Load all items in android RecyclerView at once












2















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();

}









share|improve this question

























  • Use Glide. bumptech.github.io/glide/int/recyclerview.html

    – Sourav Bagchi
    Nov 14 '17 at 15:42











  • Post your implementation of onBindViewHolder and whatever method/AsyncTask/whatever you are using to load media. I need to see exactly how you are loading the images and videos before I can help you.

    – Leo Aso
    Nov 14 '17 at 15:47











  • @Leo thank's for your help . question edited

    – b4hr4m
    Nov 14 '17 at 15:55











  • Does downloadPhoto take any arguments? Like a URL?

    – Leo Aso
    Nov 14 '17 at 15:58











  • yeah . downloadPhoto() is downloded any photo from internet (url) . in fact i got delay in download photo's

    – b4hr4m
    Nov 14 '17 at 15:59


















2















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();

}









share|improve this question

























  • Use Glide. bumptech.github.io/glide/int/recyclerview.html

    – Sourav Bagchi
    Nov 14 '17 at 15:42











  • Post your implementation of onBindViewHolder and whatever method/AsyncTask/whatever you are using to load media. I need to see exactly how you are loading the images and videos before I can help you.

    – Leo Aso
    Nov 14 '17 at 15:47











  • @Leo thank's for your help . question edited

    – b4hr4m
    Nov 14 '17 at 15:55











  • Does downloadPhoto take any arguments? Like a URL?

    – Leo Aso
    Nov 14 '17 at 15:58











  • yeah . downloadPhoto() is downloded any photo from internet (url) . in fact i got delay in download photo's

    – b4hr4m
    Nov 14 '17 at 15:59
















2












2








2








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();

}









share|improve this question
















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();

}






android android-recyclerview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '17 at 16:01







b4hr4m

















asked Nov 14 '17 at 15:38









b4hr4mb4hr4m

276520




276520













  • Use Glide. bumptech.github.io/glide/int/recyclerview.html

    – Sourav Bagchi
    Nov 14 '17 at 15:42











  • Post your implementation of onBindViewHolder and whatever method/AsyncTask/whatever you are using to load media. I need to see exactly how you are loading the images and videos before I can help you.

    – Leo Aso
    Nov 14 '17 at 15:47











  • @Leo thank's for your help . question edited

    – b4hr4m
    Nov 14 '17 at 15:55











  • Does downloadPhoto take any arguments? Like a URL?

    – Leo Aso
    Nov 14 '17 at 15:58











  • yeah . downloadPhoto() is downloded any photo from internet (url) . in fact i got delay in download photo's

    – b4hr4m
    Nov 14 '17 at 15:59





















  • Use Glide. bumptech.github.io/glide/int/recyclerview.html

    – Sourav Bagchi
    Nov 14 '17 at 15:42











  • Post your implementation of onBindViewHolder and whatever method/AsyncTask/whatever you are using to load media. I need to see exactly how you are loading the images and videos before I can help you.

    – Leo Aso
    Nov 14 '17 at 15:47











  • @Leo thank's for your help . question edited

    – b4hr4m
    Nov 14 '17 at 15:55











  • Does downloadPhoto take any arguments? Like a URL?

    – Leo Aso
    Nov 14 '17 at 15:58











  • yeah . downloadPhoto() is downloded any photo from internet (url) . in fact i got delay in download photo's

    – b4hr4m
    Nov 14 '17 at 15:59



















Use Glide. bumptech.github.io/glide/int/recyclerview.html

– Sourav Bagchi
Nov 14 '17 at 15:42





Use Glide. bumptech.github.io/glide/int/recyclerview.html

– Sourav Bagchi
Nov 14 '17 at 15:42













Post your implementation of onBindViewHolder and whatever method/AsyncTask/whatever you are using to load media. I need to see exactly how you are loading the images and videos before I can help you.

– Leo Aso
Nov 14 '17 at 15:47





Post your implementation of onBindViewHolder and whatever method/AsyncTask/whatever you are using to load media. I need to see exactly how you are loading the images and videos before I can help you.

– Leo Aso
Nov 14 '17 at 15:47













@Leo thank's for your help . question edited

– b4hr4m
Nov 14 '17 at 15:55





@Leo thank's for your help . question edited

– b4hr4m
Nov 14 '17 at 15:55













Does downloadPhoto take any arguments? Like a URL?

– Leo Aso
Nov 14 '17 at 15:58





Does downloadPhoto take any arguments? Like a URL?

– Leo Aso
Nov 14 '17 at 15:58













yeah . downloadPhoto() is downloded any photo from internet (url) . in fact i got delay in download photo's

– b4hr4m
Nov 14 '17 at 15:59







yeah . downloadPhoto() is downloded any photo from internet (url) . in fact i got delay in download photo's

– b4hr4m
Nov 14 '17 at 15:59














2 Answers
2






active

oldest

votes


















1














As you describe, you only want to load photos when the item is visible. In fact RecyclerView adapter will only invoke onBindViewHolder when the item appears(visible) so you can start download photos then update UI when photo ready for you. And you now do not load all item's photo at once, you just load when you need.



ps: If the item's photo url is known, you can use Glide or Picasso library.






share|improve this answer


























  • yeah i know this . it mean it's not possible to invoke onBindViewHolde for all items (visible or invisible) at once ?

    – b4hr4m
    Nov 14 '17 at 16:06











  • You can load at once but it should be avoided because bitmap costs many memory.

    – CoXier
    Nov 14 '17 at 16:07











  • i know this warning . can you tell me how can load all at once ?

    – b4hr4m
    Nov 14 '17 at 16:08






  • 1





    Are you sure to load all photos to memory?If so, you can load all photos when construct the adapter.

    – CoXier
    Nov 14 '17 at 16:10











  • it mean we can not invoke onBind for invisible item's . thank you :)

    – b4hr4m
    Nov 14 '17 at 16:11



















0














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.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47289700%2fload-all-items-in-android-recyclerview-at-once%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    As you describe, you only want to load photos when the item is visible. In fact RecyclerView adapter will only invoke onBindViewHolder when the item appears(visible) so you can start download photos then update UI when photo ready for you. And you now do not load all item's photo at once, you just load when you need.



    ps: If the item's photo url is known, you can use Glide or Picasso library.






    share|improve this answer


























    • yeah i know this . it mean it's not possible to invoke onBindViewHolde for all items (visible or invisible) at once ?

      – b4hr4m
      Nov 14 '17 at 16:06











    • You can load at once but it should be avoided because bitmap costs many memory.

      – CoXier
      Nov 14 '17 at 16:07











    • i know this warning . can you tell me how can load all at once ?

      – b4hr4m
      Nov 14 '17 at 16:08






    • 1





      Are you sure to load all photos to memory?If so, you can load all photos when construct the adapter.

      – CoXier
      Nov 14 '17 at 16:10











    • it mean we can not invoke onBind for invisible item's . thank you :)

      – b4hr4m
      Nov 14 '17 at 16:11
















    1














    As you describe, you only want to load photos when the item is visible. In fact RecyclerView adapter will only invoke onBindViewHolder when the item appears(visible) so you can start download photos then update UI when photo ready for you. And you now do not load all item's photo at once, you just load when you need.



    ps: If the item's photo url is known, you can use Glide or Picasso library.






    share|improve this answer


























    • yeah i know this . it mean it's not possible to invoke onBindViewHolde for all items (visible or invisible) at once ?

      – b4hr4m
      Nov 14 '17 at 16:06











    • You can load at once but it should be avoided because bitmap costs many memory.

      – CoXier
      Nov 14 '17 at 16:07











    • i know this warning . can you tell me how can load all at once ?

      – b4hr4m
      Nov 14 '17 at 16:08






    • 1





      Are you sure to load all photos to memory?If so, you can load all photos when construct the adapter.

      – CoXier
      Nov 14 '17 at 16:10











    • it mean we can not invoke onBind for invisible item's . thank you :)

      – b4hr4m
      Nov 14 '17 at 16:11














    1












    1








    1







    As you describe, you only want to load photos when the item is visible. In fact RecyclerView adapter will only invoke onBindViewHolder when the item appears(visible) so you can start download photos then update UI when photo ready for you. And you now do not load all item's photo at once, you just load when you need.



    ps: If the item's photo url is known, you can use Glide or Picasso library.






    share|improve this answer















    As you describe, you only want to load photos when the item is visible. In fact RecyclerView adapter will only invoke onBindViewHolder when the item appears(visible) so you can start download photos then update UI when photo ready for you. And you now do not load all item's photo at once, you just load when you need.



    ps: If the item's photo url is known, you can use Glide or Picasso library.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 14 '17 at 16:06

























    answered Nov 14 '17 at 16:03









    CoXierCoXier

    6771629




    6771629













    • yeah i know this . it mean it's not possible to invoke onBindViewHolde for all items (visible or invisible) at once ?

      – b4hr4m
      Nov 14 '17 at 16:06











    • You can load at once but it should be avoided because bitmap costs many memory.

      – CoXier
      Nov 14 '17 at 16:07











    • i know this warning . can you tell me how can load all at once ?

      – b4hr4m
      Nov 14 '17 at 16:08






    • 1





      Are you sure to load all photos to memory?If so, you can load all photos when construct the adapter.

      – CoXier
      Nov 14 '17 at 16:10











    • it mean we can not invoke onBind for invisible item's . thank you :)

      – b4hr4m
      Nov 14 '17 at 16:11



















    • yeah i know this . it mean it's not possible to invoke onBindViewHolde for all items (visible or invisible) at once ?

      – b4hr4m
      Nov 14 '17 at 16:06











    • You can load at once but it should be avoided because bitmap costs many memory.

      – CoXier
      Nov 14 '17 at 16:07











    • i know this warning . can you tell me how can load all at once ?

      – b4hr4m
      Nov 14 '17 at 16:08






    • 1





      Are you sure to load all photos to memory?If so, you can load all photos when construct the adapter.

      – CoXier
      Nov 14 '17 at 16:10











    • it mean we can not invoke onBind for invisible item's . thank you :)

      – b4hr4m
      Nov 14 '17 at 16:11

















    yeah i know this . it mean it's not possible to invoke onBindViewHolde for all items (visible or invisible) at once ?

    – b4hr4m
    Nov 14 '17 at 16:06





    yeah i know this . it mean it's not possible to invoke onBindViewHolde for all items (visible or invisible) at once ?

    – b4hr4m
    Nov 14 '17 at 16:06













    You can load at once but it should be avoided because bitmap costs many memory.

    – CoXier
    Nov 14 '17 at 16:07





    You can load at once but it should be avoided because bitmap costs many memory.

    – CoXier
    Nov 14 '17 at 16:07













    i know this warning . can you tell me how can load all at once ?

    – b4hr4m
    Nov 14 '17 at 16:08





    i know this warning . can you tell me how can load all at once ?

    – b4hr4m
    Nov 14 '17 at 16:08




    1




    1





    Are you sure to load all photos to memory?If so, you can load all photos when construct the adapter.

    – CoXier
    Nov 14 '17 at 16:10





    Are you sure to load all photos to memory?If so, you can load all photos when construct the adapter.

    – CoXier
    Nov 14 '17 at 16:10













    it mean we can not invoke onBind for invisible item's . thank you :)

    – b4hr4m
    Nov 14 '17 at 16:11





    it mean we can not invoke onBind for invisible item's . thank you :)

    – b4hr4m
    Nov 14 '17 at 16:11













    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 16:59









        Philipp PoropatPhilipp Poropat

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47289700%2fload-all-items-in-android-recyclerview-at-once%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]