Skip to content Skip to sidebar Skip to footer

How To Differentiate Read And Unread Messages In Android Listview?

SimpleCursorAdapter is used in my code. Cursor contains field read (true/false). If it is true, then row should be shown with grey text color, if false - with white.

Solution 1:

If it's as easy as that you've written you can use setViewBinder/setViewValue in your SimpleCursorAdapter. The following will show a TextView of the row-layout that get's painted in red if a column in your cursor holds some value of interest to you. If there are more fields you need to apply some minor changes. return true if you set own values, return false if Android should paint:

... create SimpleCursorAdapter
if (simpleCursorAdapter != null) {
  simpleCursorAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {

    @Override
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
      TextView textView = (TextView) view;

      long l = cursor.getLong(positionOfReadValue);
      if (l == valueOfRead) {
        textView.setTextColor(Color.RED);
      }

      return false;
    }

  } );

  setListAdapter(simpleCursorAdapter);
}
...

Post a Comment for "How To Differentiate Read And Unread Messages In Android Listview?"