0

リストビューで非同期ロードイメージに取り組んでいますチュートリアルを検索した後、次のコードを実装しました:

    package com.example.json;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;

public class ImgAdapter extends AsyncTask<ImageView, Void, Bitmap> {

    ImageView imageView = null;

    @Override
    protected Bitmap doInBackground(ImageView... imageViews) {
        this.imageView = imageViews[0];
        return download_Image((String) imageView.getTag());
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }

    private Bitmap download_Image(String url) {

        Bitmap bmp = null;
        try {
            URL ulrn = new URL(url);
            HttpURLConnection con = (HttpURLConnection) ulrn.openConnection();
            InputStream is = con.getInputStream();
            bmp = BitmapFactory.decodeStream(is);
            if (null != bmp)
                return bmp;

        } catch (Exception e) {
        }
        return bmp;
    }
}

問題は、アダプターで呼び出すと、クラスに execute メソッドがないことです。なぜですか?また、問題を解決するにはどうすればよいですか? ありがとう。

if (entry.image_url != null) {
    thumbnail.setTag(entry.image_url);
    new ImgAdapter.execute(entry.image_url);

} else {
    thumbnail.setVisibility(View.GONE);
}
4

2 に答える 2

1

試す:

thumbnail.setTag(entry.image_url);
new ImgAdapter().execute(thumbnail);

メソッド execute() は、doInBackground() で宣言されたものと同じ引数のリストを受け取ります。コードでは、(通常は 1 つの) ImageView のリストです。

コードは、imageView のタグに画像の URL が含まれていることを期待しています( (String) imageView.getTag() に従って)。

于 2013-07-29T10:41:22.323 に答える
0

これを as として呼び出し、url を Static として作成し、その Async 関数にアクセスして、ur Image updater を as として呼び出すことができます。

new ImgAdapter().execute();

于 2013-07-29T10:42:08.810 に答える