How does CursorAdapter work on android in GridView

后端 未结 3 1373
难免孤独
难免孤独 2021-01-19 13:59

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.

3条回答
  •  遇见更好的自我
    2021-01-19 14:44

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        ImageView iView = new ImageView(context);
        iView.setLayoutParams(new GridView.LayoutParams(200, 200));
        taskA++;
        Log.w("task s", taskA+ " count");
        return iView;
    }
    

    note, i removed all the code that isn't supposed to be in newView (it should be in bindView) replace new GridView.LayoutParams(200, 200) with whatever height/width you need, don't use wrap content as your content is empty at the beginning, resulting in 0x0 pixels, so ALL of the ImageViews from your cursor fit into the GridView at once (thus newView and bindView get called for every view)

提交回复
热议问题