ViewHolder pattern correctly implemented in custom CursorAdapter?

后端 未结 3 1426
既然无缘
既然无缘 2020-12-05 00:15

Here is my custom CursorAdapter:

public class TasksAdapter extends CursorAdapter implements Filterable {

    private final Context context;

    public Task         


        
3条回答
  •  青春惊慌失措
    2020-12-05 01:01

    My implementation of a class extends SimpleCursorAdapter with newView and bindView but without the ViewHolder pattern

        private class CountriesAdapter extends SimpleCursorAdapter {
    
                private LayoutInflater mInflater;
    
                public CountriesAdapter(Context context, int layout, Cursor cursor, String[] from,
                        int[] to, LayoutInflater inflater) {
                    super(getActivity(), layout, cursor, from, to, CURSOR_ADAPTER_FLAGS);
                    mInflater = inflater;
                }
    
                @Override
                public View newView(Context context, Cursor cursor, ViewGroup parent) {
                    return mInflater.inflate(R.layout.countries_list_row, parent, false);
                }
    
                @Override
                public void bindView(View rowView, Context context, Cursor cursor) {
    
                    TextView tvCountry = (TextView) rowView.findViewById(R.id.countriesList_tv_countryName);
                    TextView tvOrgs = (TextView) rowView.findViewById(R.id.countriesList_tv_orgNames);
                    ImageView ivContinent =
                            (ImageView) rowView.findViewById(R.id.countriesList_iv_continentName);
    
                    // TODO: set texts of TextViews and an icon here
                    }
    
                }
        }
    

提交回复
热议问题