Reputation: 75
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 ?
Upvotes: 1
Views: 573
Reputation: 372
change line
tv = (TextView)view.findViewById(R.id.countryTextView); // <-- add 'view.'
call
conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder
)
setListAdapter(conAdapter); // set adapter
Upvotes: 0
Reputation: 3645
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;
}
Upvotes: 0