Dynamically adding Images to GridView

by Gaurav » Sat, 14 Mar 2009 02:09:50 GMT

Sponsored Links
 I have a Gallery and a GridView in my application. Gallery's adapter
is based on thumbnail cursor created through query using

I use this Gallery to choose images to display in GridView. Whenever
the user clicks on an  image in the Gallery I have to add this image
to GridView. Currently, I use an ArrayAdapter<Integer> to store the
images in the GridView. The value stored as objects in the
ArrayAdapter is the _ID of the thumbnail and getView on GridView looks
like this:

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

                ImageView i = new ImageView(mContext);

                System.out.println("I am in get view:" + position);
                int thumbnailId = getItem(position);
"" + thumbnailId));
                i.setLayoutParams(new GridView.LayoutParams(80, 80));
                return i;

Whenever I click on an item in Gallery, getView is called for all
visible positions in the GridView (9 images). After, 12-13 images are
added to the gridview and I scroll up and down, I get an
OutOfMemoryError. Can someone suggest how I can rework to avoid memory
errors here.

03-13 02:29:45.456: ERROR/dalvikvm-heap(487): 338322-byte external
allocation too large for this process.
03-13 02:29:45.456: ERROR/(487): VM won't let us allocate 338322 bytes
03-13 02:29:45.466: DEBUG/skia(487): xxxxxxxxxxxxxxxxxxxx
allocPixelRef failed
03-13 02:29:58.845: DEBUG/AndroidRuntime(487): Shutting down VM
03-13 02:29:58.845: WARN/dalvikvm(487): threadid=3: thread exiting
with uncaught exception (group=0x4000fe68)
03-13 02:29:58.845: ERROR/AndroidRuntime(487): Uncaught handler:
thread main exiting due to uncaught exception
03-13 02:29:59.045: ERROR/AndroidRuntime(487):
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at
android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at


Other Threads

1. How can i get related email info through Google AuthSub token

hi there, i can get user Account token from Android AccountManager API, how
can i get the related email info from this AuthSub token? i've found  no
appropriate GData API so far

Why should i do this? i need to make sure the token and email are paired to
avoid a fake token which not related to the email account


2. convert .dex file to java back to .dex

I need to decompile a .dex file back into java to edit it and
recompile it back into .dex.

I then need to put all the files back into the .apk format.

How would I do this?

Thanks for helping.


3. Adapter drop down clipped on floating window

4. Switching between normal view and glsurfaceview (game loading screen)

5. Best way to override values in frameworks/base/core/res/res/values/config.xml ?

6. Simple question on saving to a file on sd card (android-beginners isn't working)

7. How force application(game) change multimedia volume not ringtone one