0

尝试更改 listView 图像项源取决于一个字段,例如: if (status === 1) 显示红色图像,否则显示绿色图像。我尝试了一个带有简单光标适配器的视图活页夹,但是什么也没做也没有显示任何错误

private class MyViewBinder implements SimpleCursorAdapter.ViewBinder {

    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

        int viewId = view.getId();
        int status = cursor.getInt(cursor.getColumnIndex(LoanDb.KEY_STATUS));
        ImageView noteTypeIcon = (ImageView) view;

        if(viewId == R.id.status_img) {

            switch (status) {
                case 0:
                    noteTypeIcon.setImageResource(R.drawable.red_dot);
                    break;
                case 1:
                    noteTypeIcon.setImageResource(R.drawable.green_dot);
                    break;
            }
            return true;
        }else
        {
            return false;
        }
    }

}

这个类作为子类位于 Main Activity 中,无法理解为什么这不起作用。

4

0 回答 0