phpMyAdmin
 sql >> Teknologi Basis Data >  >> Database Tools >> phpMyAdmin

Studio Android Muat url Gambar ke tampilan daftar

Saya memiliki masalah yang sama. Saya menyelesaikannya dengan AsyncTask yang mengunduh bitmap.

Saya menggunakan kode ini:

class ImageDownloaderTask extends AsyncTask<String, Void, Bitmap> {

    private final WeakReference<ImageView> imageViewReference;

    public ImageDownloaderTask(ImageView imageView) {
        imageViewReference = new WeakReference<ImageView>(imageView);
    }

    @Override
    protected Bitmap doInBackground(String... params) {
        return downloadBitmap(params[0]);
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        if (isCancelled()) {
            bitmap = null;
        }

        if (imageViewReference != null) {
            ImageView imageView = imageViewReference.get();
            if (imageView != null) {
                if (bitmap != null) {
                    imageView.setImageBitmap(bitmap);
                } else {
                    Drawable placeholder = null;
                    imageView.setImageDrawable(placeholder);
                }
            }
        }
    }

    private Bitmap downloadBitmap(String url) {
        HttpURLConnection urlConnection = null;
        try {
            URL uri = new URL(url);
            urlConnection = (HttpURLConnection) uri.openConnection();

            final int responseCode = urlConnection.getResponseCode();
            if (responseCode != HttpURLConnection.HTTP_OK) {
                return null;
            }

            InputStream inputStream = urlConnection.getInputStream();
            if (inputStream != null) {
                Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                return bitmap;
            }
        } catch (Exception e) {
            urlConnection.disconnect();
            Log.w("ImageDownloader", "Errore durante il download da " + url);
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
        }
        return null;
    }
}

Anda menyebutnya dengan:

new ImageDownloaderTask(holder.imageView).execute(urlPhoto);

Semoga membantu :)



  1. DBeaver
  2.   
  3. phpMyAdmin
  4.   
  5. Navicat
  6.   
  7. SSMS
  8.   
  9. MySQL Workbench
  10.   
  11. SQLyog
  1. Mengapa nama tabel saya diubah menjadi huruf kecil di phpmyadmin?

  2. Kesalahan penguraian data org.json.JSONException:Nilai <!DOCTYPE tipe java.lang.String tidak dapat dikonversi ke JSONObject

  3. PHPMyAdmin 500 Internal Server Error di Apache karena Versi PHP

  4. Cara menulis informasi dari formulir html ke Database MySQL

  5. Bagaimana cara mengaktifkan mysqli dengan wampserver?