I am new to android. I have more than thousand images in a directory. I am showing images thumb in grid view. With following code It's works. but the problem is it takes 45 second to load the view. I need it as: Display grid with loader and load Images one by one. So user can not wait for last image to load.
The code is:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListRowHolder listRowHolder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.ll_sponsor_list_item,
parent, false);
listRowHolder = new ListRowHolder();
listRowHolder.imgSponsor = (ImageView) convertView
.findViewById(R.id.imggrid_item_image);
convertView.setTag(listRowHolder);
} else {
listRowHolder = (ListRowHolder) convertView.getTag();
}
try {
listRowHolder.imgSponsor
.setImageBitmap(decodeSampledBitmapFromResource(
ImageName.get(position)));
} catch (Exception e) {
Toast.makeText(ctx, e + "", Toast.LENGTH_SHORT).show();
}
return convertView;
}
public static Bitmap decodeSampledBitmapFromResource(String fileName) {
Bitmap picture = BitmapFactory.decodeFile(fileName);
int width = picture.getWidth();
int height = picture.getWidth();
float aspectRatio = (float) width / (float) height;
int newWidth = 98;
int newHeight = (int) (98 / aspectRatio);
return picture = Bitmap.createScaledBitmap(picture, newWidth,
newHeight, true);
}