Getting size in BaseAdapter.getView ()

I have an Activity that contains a ListView, the list is the thumbnail on the left and the text on the right is basically like a contact list.
enter image description here
The thing is, the thumbnail is loading from the absolute path from the SD card and each image size is about 5MB. To avoid running out of memory, I created classes in this tutorial that only load the scaled version of the images and don't take up much memory.

Well, what's the problem? Since I need to pass the width and height (in pixels) that I want the image to be resized, but for different devices I would have a problem setting absolute values. So, I just tried to pass the view through args and just manipulate it in my class to get the width and height, okay, huh? Ok, but it didn't work, since the thumbnail was not a draw (think), I can't take its dimensional values.

How can I get the size inside the getView () method from my lisview adapter?

/** short passage of getView() method */
ImageView image = (ImageView) view.findViewById(R.id.image_thumb);
Bitmap bMap = BitmapAdjusted.decodeSampleBitmap("/sdcardpath/", 
            image); // "image" is the view passed by args
image.setImageBitmap(bMap);

      

Here's the problem:

public static decodeSimpleBitmap(String path, View view){
    /** unworth previous code */
    int width = view.getWidth(); // always give zero, getMeasuredWidth() too
    int height = view.getHeight(); // always give zero
    // options is BitmapFactory.Options class, declared before that do the magic
    options.inSampleSize = calculateInSampleSize(options, width, height);

}

      

Thank!

+3


source to share





All Articles