Load Image in ImageView from URL stored in JSONString in Android

前端 未结 5 694
梦如初夏
梦如初夏 2021-01-13 13:31

I have a JSON string, say a name and a Url . I need to extract name into the TextView and extract and display image in ImageView. Belo

5条回答
  •  隐瞒了意图╮
    2021-01-13 14:21

    First of all use Gson to parse Json and get url as a String, then you can use UniversalImageLoader library (it does the async image download and very easy to use) https://github.com/nostra13/Android-Universal-Image-Loader

    static public DisplayImageOptions options= new DisplayImageOptions.Builder().cacheOnDisk(true).cacheInMemory(true).build();
        imageLoader.displayImage(imgUrl, ivImage, options, new ImageLoadingListener() {
    
            public void onLoadingStarted(String imageUri, View view) {
                ((ImageView)view).setImageResource(R.drawable.nofoto);
            }
    
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                ((ImageView)view).setImageResource(R.drawable.nofoto);
            }
    
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
    
            }
    
            public void onLoadingCancelled(String imageUri, View view) {
            }
    
        });
    

提交回复
热议问题