Question

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?

// 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;          
        }};
Was it helpful?

Solution

Did you call 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.'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top