0

i have a gallery view, with a BaseAdapter, and i download images from internet, download the image, and set to gallery async. There are about 2000 images. When i rotate the screen, the asyntask continues, but the gallery set empty and dont show any now or old image.

This is the code of BaseAdapter:

private class AdaptadorImagenes extends BaseAdapter {

        private Context contexto = null;
        private ArrayList<Integer> datos = new ArrayList<Integer>();

        public AdaptadorImagenes(Context contexto) {

            this.contexto = contexto;
        }

        public void addItem(Integer posicion) {

            datos.add(posicion);
            notifyDataSetChanged();
        }

        @Override
        public int getCount() {
            return datos.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ImageView imagen = new ImageView(contexto);
            imagen.setImageBitmap(getBitMapRedimensionado(position));
            imagen.setScaleType(ScaleType.FIT_XY);
            return imagen;

        }

        /**
         * Metodo para redimensionar un bimap
         * 
         * @param posicion
         *            del bitmap en una lista que contiene los path
         * @return bitmap redimensionado
         */
        private Bitmap getBitMapRedimensionado(int posicion) {

            File fichero = new File(pathImagenes.get(posicion));
            Bitmap bmOriginal = redondeaEsquinasBitmap(Bitmap
                    .createScaledBitmap(
                            BitmapFactory.decodeFile(fichero.toString()), 210,
                            210, true));

            return bmOriginal;
        }

        /**
         * Metodo para redondear las esquinas de un bitmap
         * 
         * @param bitmap
         *            a redondear
         * @return bitmap redondeado
         */
        public Bitmap redondeaEsquinasBitmap(Bitmap bitmap) {
            Bitmap salida = Bitmap.createBitmap(bitmap.getWidth(),
                    bitmap.getHeight(), Config.ARGB_8888);


Canvas canvas = new Canvas(salida);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(),
                bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        final float roundPx = 12;

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        return salida;
    }

}

In the Manifiest i set android:configChanges="keyboardHidden|orientation"

I think save in a variable how many images have downloaded yet and when rotate the screen set all the images, but when are more than 500 this process is very slow.

Any idea?Thanks

colymore
  • 11,776
  • 13
  • 48
  • 90

1 Answers1

0

Have a look at ImageLoader. This links can help Lazy load of images in ListView or http://androidimageloader.com/

Also you can dismiss changing orientation in the AndroidManifest in activity:

android:name="com.example.MainActivity" android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait"
Community
  • 1
  • 1
validcat
  • 6,158
  • 2
  • 29
  • 38