Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从非定向URL下载图像_Android_Image - Fatal编程技术网

Android 如何从非定向URL下载图像

Android 如何从非定向URL下载图像,android,image,Android,Image,使用Android Studio我想从URL下载图像,我的意思是这些图像都在这个URL中。我有代码,但是是直接下载的。 我必须在自定义列表视图中显示它们。 代码如下: ImageView img = (ImageView) rowView.findViewById(R.id.enclosure); try { URL url = new URL("MY_URL"); <-- the URL where I want to get the images in encl

使用
Android Studio
我想从
URL
下载
图像
,我的意思是这些
图像
都在这个URL中。我有代码,但是是直接下载的。 我必须在自定义列表视图中显示它们。 代码如下:

ImageView img = (ImageView) rowView.findViewById(R.id.enclosure);
    try {
        URL url = new URL("MY_URL"); <-- the URL where I want to get the images in enclosures
        HttpGet httpRequest = null;

        httpRequest = new HttpGet(url.toURI());

        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = (HttpResponse) httpclient
                .execute(httpRequest);

        HttpEntity entity = response.getEntity();
        BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
        InputStream input = b_entity.getContent();

        Bitmap bitmap = BitmapFactory.decodeStream(input);

        img.setImageBitmap(bitmap);

    } catch (Exception ex) {

    }

但是没有显示
图像。

据我所知,这是在尝试解码整个页面的输入流,这不起作用,因为页面不仅仅是一个图像;还有文本等等。这行不通。您必须获取要下载的每个图像的URL,然后分别下载这些图像。

因此,首先我必须获取URL图像的字符串,然后按字符串下载它们。我非常感谢您的帮助:)请原谅我的混乱,但没有人能回答我的另一个问题,可以吗?由于我必须获取这些
URL的
字符串
,我创建了另一个
文本视图
,然后替换
URL URL=新URL(“我的URL”)
I put
URL URL=newurl(context.getString(R.id.my_new_textview))。这是正确的吗?因为没有显示图像。为什么要尝试在文本视图中显示图像?你放的东西只会显示。。。嗯,我不知道是什么。你的资源指向一个ID,所以我不知道会发生什么。无论如何,第一件事是:您需要使用ImageView。这是你需要知道的一个基本概念。我仍然在使用上面的代码,但只在
URL=newurl(“MY_-URL”)
I put
URL URL=newurl(context.getString(R.id.my_new_textview))因为要显示
图像
图像视图
必须参考
URL
。我错了吗?如果不是,我还能做什么?
ImageView img = (ImageView) rowView.findViewById(R.id.enclosure);
img.setImageDrawable(web.get(position).getEnclosure());