使用SimpleCursorAdapter.ViewBinder更改listView中的颜色。安卓

时间:2013-01-11 19:37:44

标签: android listview android-listview android-viewbinder

我试图改变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;          
        }};

1 个答案:

答案 0 :(得分:1)

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

同时更改其中一行:

       tv = (TextView)view.findViewById(R.id.countryTextView); // <-- add 'view.'
相关问题