0

これが私の活動です。

private ImageLoader testing;
testing = new ImageLoader(this);
imageview = (ImageView)findViewById(R.id.image_alllatestnewstitle);
...
...
...

これはリストビューなので、複数の画像が表示されます。

private void filldata() {
    lv = (ListView) findViewById(android.R.id.list);

    String[] from = new String[] { "particularlatestnewstitle",
            "newscategorytitle", "newsdate" };
    int[] to = new int[] { R.id.text_particularlatestnewstitle,
            R.id.text_newscategorytitle, R.id.text_newsdate };

    fillMaps = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < webservice.news.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("particularlatestnewstitle", webservice.news.get(i)
                .getNtitle());
        map.put("newscategorytitle", webservice.news.get(i).getNewCatName());
        map.put("newsdate", webservice.news.get(i).getNArticalD());

        fillMaps.add(map);
        imageview = (ImageView)findViewById(R.id.image_alllatestnewstitle);
        imageview.setTag(imagepath[i]);
        testing.DisplayImage(imagepath[i], imageview);
    }
    SimpleAdapter adapter = new SimpleAdapter(this, fillMaps,
            R.layout.main_alllatestnewslist, from, to);
    lv.setAdapter(adapter);

これは私の ImageLoader クラスです

public void DisplayImage(String url, ImageView imageView)
{
    imageViews.put(imageView, url);
    Bitmap bitmap=memoryCache.get(url);
    if(bitmap!=null){
        System.out.println(url.toString());
        System.out.println(bitmap.toString());
        imageView.setImageBitmap(bitmap);
    }else
    {
        queuePhoto(url, imageView);
    }
}

これはxmlレイアウトです

<ImageView
    android:id="@+id/image_alllatestnewstitle"
    android:layout_width="134px"
    android:layout_height="80px"
    android:layout_marginBottom="5px"
    android:layout_marginLeft="10px"
    android:layout_marginRight="10px"
    android:layout_marginTop="5px"
    android:scaleType="centerCrop" />

結果を印刷しました

url and bitmap

null ではなく、正しい URL リンクを表示します。

しかし、imagebitmapを設定すると、エラーは発生しませんでしたが、imageviewにも画像が表示されませんでした。

何が問題ですか?

p/s: 必要に応じて追加のコードをリクエストしてください。

4

2 に答える 2

0

このコードを試してdonwload image、画像を に設定してくださいimageview

       try {
            URL url = new URL(urlStr);
            URLConnection ucon = url.openConnection();

            InputStream is = ucon.getInputStream();
            Bitmap bitmap = BitmapFactory.decodeStream(is);
            if(bitmap!=null){
                System.out.println(url.toString());
                System.out.println(bitmap.toString());
                imageView.setImageBitmap(bitmap);
            }
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
于 2012-05-07T11:17:53.310 に答える
0

Fedor の遅延読み込みロジックを使用していると思います。

そして今、あなたが提供したコードに基づいて、私は 1 つのことを言うことができます。つまり、DisplayImage() メソッドを呼び出す前に TAG を ImageView に設定するのを忘れていました。

testing.setTag(imagepath[i]);
于 2012-05-07T11:11:14.033 に答える