What I have
I have an “open image dialog” in an activity. This “dialog” only shows folders and compatible images. For this I have a layer with a gridview that I fill with rows that contains an image and a text.
The text is for the name of the file and the image is for a preview of the image.
My problem
The dialog works well if the folder that I’m seeing doesn’t have lots of images. I’m working on a SII and when I try to open the camera album (photos of 8Mpx) it goes very slow with my code, even each time a new row is redrawed.
My code
I think the main problem resides in the creation of the preview images because if I delete this part all works fine. For the images, I have:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View grid;
if(convertView==null){
grid = new View(mContext);
LayoutInflater inflater=getLayoutInflater();
grid=inflater.inflate(R.layout.row, parent, false);
}else{
grid = (View)convertView;
}
ImageView icon = (ImageView)grid.findViewById(R.id.file_image);
TextView label = (TextView)grid.findViewById(R.id.file_text);
label.setText(item.get(position));
if (item.get(position).equals("/")){
icon.setImageResource(R.drawable.folderupup);
}else if (item.get(position).endsWith("../")) {
icon.setImageResource(R.drawable.folderup);
}else if (item.get(position).endsWith("/")) {
icon.setImageResource(R.drawable.folder);
}else{
Bitmap b = BitmapFactory.decodeFile(path.get(position));
Bitmap b2 = Bitmap.createScaledBitmap(b, 55, 55, false);
icon.setImageBitmap(b2);
}
return grid;
}
}
Finally I did all that the Android page said without doing anything for the cache. Now the list loads fast. Maybe I could add a memory cache as Wenhui pointed but it is so fast that it doesn’t matter for my purposes.
The test has been done on a SII with a folder containing around 400 with 8Mpx