1

我试图更改 ListView 中文本的颜色,所以我创建了 ViewBinder 但我的文本仍然是白色的,没有任何变化,我能用它做什么?

// map each name to a TextView
    String[] from = new String[] { "event" };
    int[] to = new int[] { R.id.countryTextView };
    conAdapter = new SimpleCursorAdapter(Clock.this, R.layout.day_plan, null, from, to);
    setListAdapter(conAdapter); // set adapter

    SimpleCursorAdapter.ViewBinder binder = new SimpleCursorAdapter.ViewBinder() {

        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex){    
            int getIndex = cursor.getColumnIndex("colour");
            String color = cursor.getString(getIndex);
           tv = (TextView)findViewById(R.id.countryTextView);

            tv.setTextColor(Color.BLUE);

           if(color.equals("Green"))
            {                   
                tv.setTextColor(Color.rgb(0,255,0));
                return true;
            } 
            return false;          
        }};
4

1 回答 1

1

你打电话了conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder)吗?也就是说,您确定这些方法实际上被调用了吗?

还要更改这些行之一:

       tv = (TextView)view.findViewById(R.id.countryTextView); // <-- add 'view.'
于 2013-01-11T19:53:13.630 回答