简体   繁体   English

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

[英]Using SimpleCursorAdapter.ViewBinder to change color in a listView. android

I was trying to change color on a text in a ListView, so I created ViewBinder but my text is still white, nothing change, what can I do with it? 我试图在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;          
        }};

Did you call conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder) ? 您是否致电conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder) That is, are you sure those methods are actually being called? 也就是说,您确定实际上正在调用这些方法吗?

Also change one of those lines: 还要更改以下几行之一:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM