1

Im trying to change text color in a listview, which is displaying my entries from database. The problem is that it displays invisible text ( or it displays nothing at all. only the lines which are separating my entries on this list) but after clicking on entry it shows me details from this entries. Displaying works good without trying to use 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);



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

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

            tv.setTextColor(Color.WHITE);

           if(empname.equals("Green"))
            {                   
                tv.setTextColor(Color.WHITE);
                return true;
            } 
            return false;          
        }


    };
    setListAdapter(conAdapter); // set adapter
    ((SimpleCursorAdapter) conAdapter).setViewBinder(binder);

How can I change it to work ok ?

apony
  • 75
  • 8

2 Answers2

0

You have to add the text to the textview:

@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) 
{
    ((TextView) view).setTextColor(Colors.RED);
    ((TextView) view).setText(cursor.getString(cursor.getColumnIndex("YOUR-COLUMN-NAME")));
    return false;
}
Goran Horia Mihail
  • 3,536
  • 2
  • 29
  • 40
0

change line

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

call

conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder)

setListAdapter(conAdapter); // set adapter
nzala
  • 374
  • 4
  • 10