undefined

實際執行程式碼:

new DownloadImageTask((ImageView) findViewById(R.id.imageView1))
            .execute("http://fassoft.com.tw/fassoft.png");

 

將以下 class 放在你的 Activity 的 class 中

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    public DownloadImageTask(ImageView bmImage) {
        this.bmImage = bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}

 

文章標籤

finalfrank 發表在 痞客邦 留言(0) 人氣()