I had a problem using the cursor adapter in gridview, which I used with the cursor to load photos from the multimedia store. I realized that my newView and bindView got full permission. I mean, assuming I have 500 photos, newView is also called the same number of times.
Did I do something wrong? I thought he would call only when the cell is 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); } }
source share