如何区分在Android的ListView的读和未读邮件?邮件、Android、ListView

由网友(你给的疼痛,我痛失了眼眸)分享简介:SimpleCursorAdapter 用在我的code。光标包含字段读(真/假)。如果这是真的,那么行应显示为灰色文本颜色,如果误 - 白色SimpleCursorAdapter is used in my code.Cursor contains field read (true/false).If...

SimpleCursorAdapter 用在我的code。 光标包含字段(真/假)。 如果这是真的,那么行应显示为灰色文本颜色,如果误 - 白色

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.

推荐答案

如果它是为你写,你可以使用setViewBinder / setViewValue在SimpleCursorAdapter一样容易。以下将显示,获得真实漆成红色行布局一个TextView如果你的光标列保存你感兴趣的一些价值。如果有更多的领域,你需要应用一些小的改动。如果设置自己的价值观,返回false,如果Android的应该绘制返回true:

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);
}
...
阅读全文

相关推荐

最新文章