How does CursorAdapter work on android in GridView

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

    I would simply extend BaseAdapter rather than Cursor Adapter and pass the fetched Data to the Adapter with a callback. Still you are not using any kind of different thread for the getThumbnail - the handler executes in the main thread and is only for updating the UI usually.

    Also you should work with ViewHolders and the convertView to speed up the Grid-Speed.

    I have something like this as BaseAdapter for every Adapter:

    public abstract class MyBaseAdapter extends BaseAdapter {
    
    protected LayoutInflater inflater;
    protected Context context;
    
    public TikBaseAdapter(Context context) {
        this.context = context;
        this.inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    
    public final View getView(int position, View convertView, ViewGroup parent) {
        int type = getItemViewType(position);
        if (convertView == null) {
            convertView = newView(type, parent);
        }
        bindView(position, type, convertView);
        return convertView;
    }
    
    /** Create a new instance of a view for the specified {@code type}. */
    public abstract View newView(int type, ViewGroup parent);
    
    /** Bind the data for the specified {@code position} to the {@code view}. */
    public abstract void bindView(int position, int type, View view);
    
    
    
    }
    

    My real Adapter overrides getItemViewType and then using switch-cases to inflate the correct layout - and work with viewHolders (view.setTag()) to speed up the scroll-performance. just use view.getTag() in the bindView method and then edit the View-Items.

提交回复
热议问题