1

我在尝试调用ImageLoader 的 DisplayImage 函数时遇到问题,实际上没有得到我需要用来显示图像的东西:

 imgLoader.DisplayImage (....);

我正在编写一个应用程序,我需要在其中将图像加载到 ImageView 中,但总是在图像的位置出现空白,请参见下图:

在此处输入图像描述

注意:我不知道我需要使用什么,在这一行:

  ImageLoader imgLoader = new ImageLoader(getApplicationContext());      
  imgLoader.DisplayImage(url, loader, imageView);

所以请给我看代码,根据我的代码,我需要写什么来在 ImageView 中显示图像

我正在使用 Localhost 来获取图像,请参阅下面的代码使用来获取图像-

private static final String URL_ALBUMS = "http://10.0.2.2/songs/albums.php";
private static final String TAG_IMAGE = "imagepath";

String image = c.getString(TAG_IMAGE);

HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_IMAGE, image);

protected void onPostExecute(String file_url) {
    // dismiss the dialog after getting all albums
    pDialog.dismiss();
    // updating UI from Background Thread
    runOnUiThread(new Runnable() {
    public void run() {
    /**
     * Updating parsed JSON data into ListView
     * */
    ListAdapter adapter = new SimpleAdapter(

    AlbumsActivity.this, albumsList,
    R.layout.list_item_albums, new String[] { TAG_ID,
    TAG_NAME, TAG_IMAGE, TAG_SONGS_COUNT }, 

    new int[] {
    R.id.album_id, R.id.album_name, R.id.list_image, R.id.songs_count });

    // ImageLoader class instance
    ImageLoader imgLoader = new ImageLoader(getApplicationContext());

    // here i don't know how to call DisplayImage function   
    imgLoader.DisplayImage (....); // what to write here    

    // updating listview
    setListAdapter(adapter);
         }
    });

注意-我在我的项目中添加了所有必需的类,类是:

      ImageLoader.java, FileCache.java, MemoryCache.java & Utils.java

数据.php:-

 1 => array(
        "id" => 1,
        "album" => "127 Hours",
        "imageurl" => "images/onetwentyseven.png"
         ............

注意:- 如您所见,我使用的是本地图像,我存储本地图像文件夹中的图像。

JSON:-

[{"id":1,"name":"127 Hours","imagepath":"images\/onetwentyseven.png","songs_count":2},{"id":2,"name":"Adele 21","imagepath":"images\/adele.png","songs_count":2}]
4

3 回答 3

2

在AlbumsActivity.java中尝试以下代码:

ImageView thumb_image = (ImageView) findViewById(R.id.list_image);                  
ImageLoader imgLoader = new ImageLoader(getApplicationContext());      
imgLoader.DisplayImage(TAG_IMAGE, thumb_image);
于 2013-07-19T10:00:39.843 回答
1

Url = "您的图片网址" //ex:- www.abc.com/images/img.jpg

Drawable drawable = LoadImageFromWebOperations(Url);
  imageView.setImageDrawable(drawable);

private Drawable LoadImageFromWebOperations(String url) {

    try {
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
    } catch (Exception e) {
        System.out.println("Exc=" + e);
        return null;
    }

}

于 2013-07-19T06:37:44.877 回答
1
                            imageLoader = ImageLoader.getInstance();
            configuration = ImageLoaderConfiguration
                    .createDefault(getActivity());
            imageLoader.init(configuration);

            options = new DisplayImageOptions.Builder()
            .showStubImage(R.drawable.default_image)
            .showImageForEmptyUri(R.drawable.default_image)
            .showImageOnFail(R.drawable.default_image)
            .cacheInMemory().cacheOnDisc()
            .bitmapConfig(Bitmap.Config.RGB_565).build();

            imageLoader.displayImage(user_bean.getmImage(), mProfileImage,
                    options);
于 2013-07-19T07:20:26.727 回答