0

I have a gallery in my android application when I clicked on gallery item I want to display image and grid view. I done when i have only three images in gallery and in click it displayed correctly. But now I have seven images in gallery and each gallery item there are four images to display gallery.In this I m using array of drwawable images only.In this time I got an exception as Java.lang.OutOfMemory
I use below code

   public ImageThemeAdapter(Context c, Integer[] mImageIds) {
     imagesId=mImageIds;
     bitmap=new Bitmap[imagesId.length];
     mContext = c;
     TypedArray ta=obtainStyledAttributes(R.styleable.Gallery1);
        imageBackground=ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
        ta.recycle();
        for (int i = 0; i <imagesId.length; i++) {
           bitmap[i]=BitmapFactory.decodeResource(mContext.getResources(),imagesId[i]);
        }
    }

    public int getCount() {
        return bitmap.length;
    }

    public Object getItem(int position) {
        return bitmap[position];  
    }

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

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

        ImageView i = new ImageView(mContext);

        i.setImageBitmap(bitmap[position]);
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setLayoutParams(new Gallery.LayoutParams(130, 120));
       // i.setLayoutParams(new Gallery.LayoutParams((ScreenWidth*80)/100, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
        i.setBackgroundResource(imageBackground);
        return i;   
    }

please provide any suggestions. Thanks in advance. I have have a requirement like this gallery and grid view

vimalatha
  • 63
  • 1
  • 10
  • Classic android issue :) check this out : http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview – Slickelito Jul 23 '12 at 12:49

1 Answers1

0

Please repeat the steps using Allocation Tracker(Windows -> Shows View -> Other -> Android -> Allocation Tracker) and find out the memory allocation to different objects.

The main reason could be due the layout of custom view as you are creating GridView and at runtime you will be creating thumbinals of images of gallery. we might have to create a gridview with minimum number of images available at one time.

Roll no1
  • 1,315
  • 1
  • 16
  • 23