I have a problem with using cursor adapter on gridview which I used the cursor to load photos from the media store. I realized my newView and bindView got called completely. I mean assuming i have 500 photos, the newView also get called the same number of times.
Did I do anything wrong ? I thought it will only call when the cell was visible on the screen..
public int taskA = 0;
public GalleryCursorAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
int index = cursor.getColumnIndex(MediaStore.Images.Media._ID);
long id = cursor.getLong(index);
Bundle idBundle = new Bundle();
idBundle.putLong("id", id);
Message msg = new Message();
msg.setData(idBundle);
ImageHandler imgHandler = new ImageHandler(context, (ImageView) view);
imgHandler.sendMessage(msg);
view.setTag(imgHandler);
Log.w("task s", " count");
}
@SuppressLint({ "NewApi", "NewApi" })
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// TODO Auto-generated method stub
int index = cursor.getColumnIndex(MediaStore.Images.Media._ID);
long id = cursor.getLong(index);
ImageView iView = new ImageView(context);
Bundle idBundle = new Bundle();
idBundle.putLong("id", id);
Message msg = new Message();
msg.setData(idBundle);
ImageHandler imgHandler = new ImageHandler(context, iView);
imgHandler.sendMessage(msg);
iView.setTag(imgHandler);
taskA++;
Log.w("task s", taskA+ " count");
return iView;
}
static class ImageHandler extends Handler {
private ImageView mView;
private Context mContext;
public ImageHandler(Context c, ImageView v) {
mView = v;
mContext = c;
}
@Override
public void handleMessage(Message msg) {
Bundle idBundle = msg.getData();
Long id = idBundle.getLong("id");
Bitmap image = MediaStore.Images.Thumbnails.getThumbnail(
mContext.getContentResolver(),
id,
MediaStore.Images.Thumbnails.MICRO_KIND,
new Options());
mView.setImageBitmap(image);
}
}