简体   繁体   中英

Image caching not in List View android

Hi guys i am stuck with image caching. i need to populate Linear Layout with images from web.

I was searching examples how to cache images in android and found these examples:

I tried it implement for my code.

    String picPath = "https://www.google.lt/logos/classicplus.png";

    try {
        /*
        View v = null;//new View(this);

        ImageLoader loader = new ImageLoader(this);
        ImageView im = (ImageView)this.findViewById(R.id.image);

        loader.DisplayImage(picPath, im);
        addImage( im);*/

          LayoutInflater inflater =(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           View convertView = inflater.inflate(R.layout.item, null);

        ImageView image = (ImageView)convertView.findViewById(R.id.image);
        ImageDownloader down = new ImageDownloader();
        down.download(picPath, image);
        addImage(image);

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    public void addImage( View view){

        LinearLayout pubLayout = (LinearLayout)findViewById( R.id.scrollerLinearlayout);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                 LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        //setting layout_margin
        params.setMargins(15, 30, 15, 30);
        pubLayout.addView(view,params);

}

However this didn't worked. I believe because i add view to linear layout and when image is downloaded it can't repaint it ?

There are examples how to do image caching using ListView. But what to do if i am not using List View.

I would write my own caching but how to make callback to image downloaded as i want first add image to layout and on callback update it ?

Thanks.

您必须在父视图上调用无效

    pubLayout.getParent().invalidate();

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