How does CursorAdapter work on android in GridView

后端 未结 3 1360
难免孤独
难免孤独 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:37

    From what I understood, you need to bind data to the View you have created. Like this:

    public class ExampleCursorAdapter extends CursorAdapter {
    public ExampleCursorAdapter(Context context, Cursor c) {
        super(context, c);
    }
    
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        TextView summary = (TextView)view.findViewById(R.id.summary);
        summary.setText(cursor.getString(
                cursor.getColumnIndex(ExampleDB.KEY_EXAMPLE_SUMMARY)));
    }
    
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.item, parent, false);
        bindView(v, context, cursor);
        return v;
    }
    }
    

提交回复
热议问题