Android 修改SimpleCorsorAdapter';s数据

Android 修改SimpleCorsorAdapter';s数据,android,android-listview,simplecursoradapter,android-viewbinder,Android,Android Listview,Simplecursoradapter,Android Viewbinder,我正在开发一个电视指南应用程序,它使用一个ListActivity一次显示一个频道/一天的电视节目。我正在为列表视图项使用相对视图,我希望列表视图看起来像这样: 07:00 The Breakfast Show Latest news and topical reports 08:00 Tom and Jerry More cat and mouse capers adapter.setViewBinder(new SimpleCursorAdapter.ViewBin

我正在开发一个电视指南应用程序,它使用一个
ListActivity
一次显示一个频道/一天的电视节目。我正在为
列表视图
项使用
相对视图
,我希望
列表视图
看起来像这样:

07:00 The Breakfast Show
      Latest news and topical reports
08:00 Tom and Jerry
      More cat and mouse capers
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
    @Override
    public boolean setViewValue(View view, Cursor cursor, int column) {
        if( column == 0 ){ // let's suppose that the column 0 is the date
            TextView tv = (TextView) view;
            String dateStr = cursor.getString(cursor.getColumnIndex("name_of_the_date_column"));
            // here you use SimpleDateFormat to bla blah blah
            tv.setText(theFormatedDate);
            return true;
        }
        return false;
    }
});
我使用以下代码获取
列表视图
项的数据:

Cursor cursor = db.rawQuery(SELECT blah,blah,blah);
String[] columnNames = new String[]{"start_time","title", "subtitle"};
int[] resIds = new int[]{R.id.start_time_short, R.id.title, R.id.subtitle};
adapter = new SimpleCursorAdapter(this, R.layout.guide_list_item, cursor, columnNames, resIds);
我的问题是
start\u time
字段是一个
datetime
字段,格式如下:

2011-01-23 07:00:00
所以我得到的是:

2011-01-23 07:00:00 The Breakfast Show
                    Latest news and topical reports
2011-01-23 08:00:00 Tom and Jerry
                    More cat and mouse capers
我要做的是使用
SimpleDateFormat
“HH:mm”
)格式化上述内容,因此我只得到
开始时间
字段的
小时:分钟
部分


我找到了
SimpleCursor.ViewBinder
界面,它表明这可能是我想要的,但我不知道如何使用它。如果我对
ViewBinder
的理解是正确的,我希望您能给我一些关于如何使用它的示例代码的提示。否则,我如何才能实现更改
开始时间
字段以简单显示
HH:mm
格式?

您可以执行以下操作:

07:00 The Breakfast Show
      Latest news and topical reports
08:00 Tom and Jerry
      More cat and mouse capers
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
    @Override
    public boolean setViewValue(View view, Cursor cursor, int column) {
        if( column == 0 ){ // let's suppose that the column 0 is the date
            TextView tv = (TextView) view;
            String dateStr = cursor.getString(cursor.getColumnIndex("name_of_the_date_column"));
            // here you use SimpleDateFormat to bla blah blah
            tv.setText(theFormatedDate);
            return true;
        }
        return false;
    }
});

谢谢,这就很好地解释了。我重新编写了你的示例,使其符合我的代码,它对我来说非常适合。这使我在尝试从光标重新排序行计数时省去了麻烦,所以谢谢你,先生。我的代码如下:HistoryAdapter.setViewBinder(新的SimpleCursorsAdapter.ViewBinder(){@Override public boolean setViewValue(视图视图、光标、int列){如果(列==0){//让我们假设列0是//日期文本视图tv=(文本视图)视图;字符串rownum=String.valueOf(Cursor.getPosition()+1);//这里您使用SimpleDataFormat来废话废话tv.setText(rownum);返回true;}返回false;}});@Cristian,请问您能帮上忙吗?