Android 根据光标结果更改listview项的背景颜色

Android 根据光标结果更改listview项的背景颜色,android,listview,simplecursoradapter,custom-lists,Android,Listview,Simplecursoradapter,Custom Lists,我有以下列表视图 private void populateKPIListView(String storedStaffId, View view, String id){ //List 1 Cursor cursor = db.getAllRows("*", dbTables.TABLE_KPIS, "WHERE projectid=" + id); int count = db.getRowCount("*", dbTables.TABLE_KPIS, "WHERE

我有以下列表视图

private void populateKPIListView(String storedStaffId, View view, String id){
    //List 1
    Cursor cursor = db.getAllRows("*", dbTables.TABLE_KPIS, "WHERE projectid=" + id);

    int count = db.getRowCount("*", dbTables.TABLE_KPIS, "WHERE projectid=" + id);

    TextView empty = (TextView)view.findViewById(android.R.id.empty);
    if(count > 0){
        empty.setVisibility(View.GONE);
        String[] fromFieldNames = new String[] {dbTables.KEY_KPIHEADER, dbTables.KEY_TARGET, dbTables.KEY_ACTUAL};
        int[] toViewIDs  = new int[] {          R.id.card_title,        R.id.card_target,    R.id.card_actual};
        myCustomAdaptor = new CustomListAdapter(getActivity(), R.layout.kpi_list_item_card, cursor, fromFieldNames, toViewIDs, 0);
        kpiList = (ListView)view.findViewById(android.R.id.list);
        kpiList.setAdapter(myCustomAdaptor);

        kpiList.setOnItemClickListener(new OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent i = new Intent(getActivity(), KpiPopUpActivity.class);
                 i.putExtra("DB_ID", id);
                 startActivity(i);

            }

        });
    }else{
        empty.setVisibility(View.VISIBLE);
        empty.setText(R.string.kpi_empty_string);
    }
}

问题是,这会将所有列表项更改为红色。日志为每个项生成相同的结果(因此它们都是红色的)。我说每个项目的目标是7,实际目标是8。实际上,我知道没有一个结果具有这些数字的实际值或目标值。

问题是,您得到的是列索引,而不是该行列中的值。请尝试以下操作:

int target = c.getInt(c.getColumnIndex(dbTables.KEY_TARGET));
int actual = c.getInt(c.getColumnIndex(dbTables.KEY_ACTUAL));

完美的为什么我总是看那些简单的东西哈哈。非常感谢。
int target = c.getInt(c.getColumnIndex(dbTables.KEY_TARGET));
int actual = c.getInt(c.getColumnIndex(dbTables.KEY_ACTUAL));