bindView()方法如何在Android SimpleCursorAdapterClass中工作

时间:2019-06-09 01:02:02

标签: android simplecursoradapter

我是Android新手。我通过遵循教程实现了ListView可滚动应用程序。但是我不明白滚动列表时SimpleCursorAdapter类中的bindView()方法如何工作。

@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;
}

0 个答案:

没有答案
相关问题