【问题标题】:downloading images from web in android在android中从网上下载图像
【发布时间】:2013-09-11 13:03:03
【问题描述】:

我正在尝试从网络下载图像并将其显示在图像视图中。 问题是屏幕上没有显示任何内容。 我正在使用下面的代码。 谢谢!

package com.example.citiestoremember;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class DisplayImage extends Activity {
ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_city);
      Intent theIntent = getIntent();

    String urlImage = theIntent.getStringExtra("urlImage");
          try {
              img = (ImageView) findViewById(R.id.urlImage);
              Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new     URL(urlImage).getContent());
              img.setImageBitmap(bitmap); 
            } catch (MalformedURLException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
}

}

【问题讨论】:

标签: android download


【解决方案1】:

ImageLoader 不是通用 ImageLoader。 Android 正在为图像加载提供 AQuery。

您可以从以下链接找到一个查询 jar 文件:

http://code.google.com/p/android-query/

私有 AQuery androidAQuery; androidAQuery = new AQuery(getActivity());

androidAQuery.id(your imageview).image(your image value, true, true,default icon(optional));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-05
    • 2013-05-11
    • 1970-01-01
    • 2015-01-26
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多