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
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI.

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);
                i.setImageURI(
Uri.withAppendedPath
(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
"" + thumbnailId));
                i.setScaleType(ImageView.ScaleType.CENTER_CROP);
                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
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304)
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at
android.graphics.drawable.Drawable.createFromStream(Drawable.java:635)
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at
android.widget.ImageView.resolveUri(ImageView.java:477)
03-13 02:29:59.045: ERROR/AndroidRuntime(487):     at

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Game online

Rr,ada ga game online buat android

Apalagi yang teamwork 

Ayuk,

Main

--
Sent from my Android phone with K-9. Please excuse my brevity.

2. Nested TabWidget ?

Hello.
I am new to Android. I just started with the layout examples and i was
wondering how to get nested TabWidgets (a TabWidget inside a tab of
another TabWidget).
I noticed that android:id="@android:id/tabs" of one TabWidget might
conflict with the other... or am i missing something?

Thanks,
Marcus.

-- 

3. Broadcast receiver for ACTION_UP of the camera button

4. how to enable this permission in my app "com.google.android.providers.gmail.permission.READ_GMAIL"

5. Clicking a link in Browser initates a new Intent

6. ListActivity not updating on Database update.

7. Clicking a link in Browser initates a new Intent