How to load image in Viewholder of MovieAdapter?

后端 未结 2 1219
北海茫月
北海茫月 2020-12-21 17:38

Main Code

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mo         


        
相关标签:
2条回答
  • 2020-12-21 18:22

    Add getter and setter methods for your Image like

    public String getImageUrl() {
            return imageUrl;
        }
    
       public void setImageUrl(String imgUrl) {
           imageUrl= imgUrl;
        }
    

    Add this code in your adapter class after adding Picasso library to your project:

    String imageUrl = movieData.get(position).getImageUrl();
    
    Picasso.with(getContext())
        .load(imageUrl)
        .into(holder.movieImage, new com.squareup.picasso.Callback() {
                            @Override
                            public void onSuccess() {
    
                            }
    
                            @Override
                            public void onError() {
    
                            }
                        });
    
    0 讨论(0)
  • 2020-12-21 18:25

    I am using this library and loading images by

    first creating the Display options object by

        DisplayImageOptions builder = new DisplayImageOptions.Builder()
                                    .cacheOnDisk(true)
                                    .showImageOnLoading(R.drawable.empty_photo)        
                                    .showImageForEmptyUri(R.drawable.empty_photo)
                                    .build();
    

    Then initialze the image loader by

      ImageLoader imageLoader = ImageLoader.getInstance();
    

    and load images by

     imageLoader.displayImage(url, imageView, builder);
    

    Hope this helps.. also add this to you gradle

      compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    

    Refer this first

    EDIT: Add this to onCreate() of activity

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
            ...
            .build();
        ImageLoader.getInstance().init(config);
    

    or this

       ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(Activity.this‌​));
    
    0 讨论(0)
提交回复
热议问题