Snake Snake - 1 year ago 57
Android Question

Why are expanding/collapsing and scrolling ExpandableListView slow?

I have an

which populates the fields of the rows as normal. However, one of the fields is an
in which the path to the image is stored in a variable. The problem is expanding/collapsing and scolling list view are slow. The expand/collapse takes around a second. Is this normal? Is there a way to make it faster? The code below is the
code which I suspect it is the reason behind the performance (I commented it and the speed was acceptable)

Please let me know what can be done.

String imagePath = prop.getImagePath();
if (imagePath.length() > 0) {
Uri mainImgeUri = Uri.parse(imagePath);
InputStream imageStream;
try {
imageStream = mActiviy.getContentResolver().openInputStream(mainImgeUri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options);
} catch (FileNotFoundException e) {

Please note that the variable prop was obtained from database which
is stored as string in DB. The DB queries happened before even initializing the list so it does not have impact the performance.

Answer Source

I'm assuming that this code block is inside the getView() method of your adapter, due to holder.main.... If so, this is a terrible practice because you should understand that this is going to be done to each one of the ExpandableList rows. The effects should be pronounced during the scrolling and expanding/collapsing because getView() would probably being called for all these rows and these images are being retrieved extraneously.

Much better is to set up a collection to hold these images and then bulk insert them once at once. Then you can use this image collection to populate your expandable List. Also consider using the convertView technique, if not already.