android-具有来自url的图像的图像库

android-具有来自url的图像的图像库,第1张

概述我想创建一个从URL获取图片的图片库.这是我的代码,但是无法正常工作…importjava.io.BufferedInputStream;importjava.io.IOException;importjava.io.InputStream;importjava.net.URL;importjava.net.URLConnection;importandroid.app.Activity;importandroid.cont

我想创建一个从URL获取图片的图片库.这是我的代码,但是无法正常工作…

import java.io.BufferedinputStream;import java.io.IOException;import java.io.inputStream;import java.net.URL;import java.net.URLConnection;import androID.app.Activity;import androID.content.Context;import androID.content.res.TypedArray;import androID.graphics.Bitmap;import androID.graphics.BitmapFactory;import androID.graphics.drawable.Drawable;import androID.os.Bundle;import androID.util.Log;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.AdapterVIEw;import androID.Widget.BaseAdapter;import androID.Widget.gallery;import androID.Widget.ImageVIEw;import androID.Widget.AdapterVIEw.OnItemClickListener;public class gallery extends Activity {    private gallery gallery;    private ImageVIEw imgVIEw;    private String[] myRemoteImages = {            "http://www.kostas-menu.gr/chania/venizelou.jpg",             "http://www.kostas-menu.gr/chania/faros.jpg",            "http://www.kostas-menu.gr/chania/giali.jpg",            "http://www.kostas-menu.gr/chania/kipos.jpg"    };    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.gallery);        imgVIEw = (ImageVIEw)findVIEwByID(R.ID.ImageVIEw01);        imgVIEw.setimageResource(myRemoteImages[0]);         gallery = (gallery) findVIEwByID(R.ID.examplegallery);         gallery.setAdapter(new AddimgAdp(this));         gallery.setonItemClickListener(new OnItemClickListener() {            public voID onItemClick(AdapterVIEw parent, VIEw v, int position, long ID) {                imgVIEw.setimageResource(myRemoteImages[position]);            }        });    }    public class AddimgAdp extends BaseAdapter {        int galItemBg;        private Context cont;        public AddimgAdp(Context c) {            cont = c;            TypedArray typArray = obtainStyledAttributes(R.styleable.gallerytheme);            galItemBg = typArray.getResourceID(R.styleable.gallerytheme_androID_galleryItemBackground, 0);            typArray.recycle();        }        public int getCount() {            return myRemoteImages.length;        }        public Object getItem(int position) {            return position;        }        public long getItemID(int position) {            return position;        }        public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) {            ImageVIEw i = new ImageVIEw(this.myContext);            try {                                /* Open a new URL and get the inputStream to load data from it. */                                URL aURL = new URL(myRemoteImages[position]);                                URLConnection conn = aURL.openConnection();                                conn.connect();                                inputStream is = conn.getinputStream();                                /* Buffered is always good for a performance plus. */                                BufferedinputStream bis = new BufferedinputStream(is);                                /* Decode url-data to a bitmap. */                                Bitmap bm = BitmapFactory.decodeStream(bis);                                bis.close();                                is.close();                                /* Apply the Bitmap to the ImageVIEw that will be returned. */                                i.setimageBitmap(bm);                        } catch (IOException e) {                                i.setimageResource(R.drawable.error);                                Log.e("DEBUGTAG", "Remtoe Image Exception", e);                        }    }}

错误是我不能使用imgVIEw.setimageResource(myRemoteImages [0]);对于字符串…请帮助吗?

解决方法:

我建议您将此LazyLoader用于从URL Lazy load of images in ListView获取的图像.

对于您的情况,我的意思是从图库视图内的Web加载图像,请使用示例链接中给出的相同适配器.

总结

以上是内存溢出为你收集整理的android-具有来自url的图像的图像库全部内容,希望文章能够帮你解决android-具有来自url的图像的图像库所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1071308.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存