如何在android ListView中区分已读和未读消息? [英] How to differentiate read and unread messages in android ListView?

查看:31
本文介绍了如何在android ListView中区分已读和未读消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SimpleCursorAdapter 在我的代码中使用.光标包含字段 read(真/假).如果为真,则行应显示为灰色文本颜色,如果为假,则显示为白色.

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.

推荐答案

如果它像您编写的一样简单,您可以在 SimpleCursorAdapter 中使用 setViewBinder/setViewValue.下面将显示行布局的 TextView,如果光标中的列包含您感兴趣的某些值,则该文本视图将被绘制为红色.如果有更多字段,您需要应用一些小的更改.如果您设置自己的值,则返回 true,如果 Android 应该绘制,则返回 false:

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);
}
...

这篇关于如何在android ListView中区分已读和未读消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆