Как работает метод bindView () в Android SimpleCursorAdapterClass - PullRequest
0 голосов
/ 09 июня 2019

Я новичок в Android.Я реализовал прокручиваемое приложение ListView, следуя инструкциям.Но я не могу понять, как работает метод bindView () в классе SimpleCursorAdapter при прокрутке списка.

@Override
public void bindView(View view, Context context, Cursor cursor) {

    super.bindView(view, context, cursor);

    ViewHolder holder = (ViewHolder) view.getTag();
    if (holder == null) {
        holder = new ViewHolder();
        holder.colImp = cursor.getColumnIndexOrThrow(RemindersDbAdapter.COL_IMPORTANT);
        holder.listTab = view.findViewById(R.id.row_tab);
        view.setTag(holder);
    }

    if (cursor.getInt(holder.colImp) > 0) {
        holder.listTab.setBackgroundColor(context.getResources().getColor(R.color.orange));
    } else {
        holder.listTab.setBackgroundColor(context.getResources().getColor(R.color.green));
    }
}

static class ViewHolder {
    //store the column index
    int colImp;
    //store the view
    View listTab;
}
...