如何处理SimpleCursorAdapter不能自动转换的数据

SimpleCursorAdapter可以把我们从Array或数据库中取出的数据绑定的ListView或其他的组件,这个很好用,但有时候有些View,SimpleCursorAdapter并不能直接绑定,需要自己去实现它的setViewBinder方法,下面是我利用SimpleCursorAdapter绑定RatingBar的例子:

SimpleCursorAdapter timeItems = new SimpleCursorAdapter(this,
                R.layout.timeitem_row, timeItemsCursor, from, to);
        timeItems.setViewBinder(new SimpleCursorAdapter.ViewBinder(){

            @Override
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                int rateIndex = cursor.getColumnIndex("rate");
                if(columnIndex == rateIndex)
                {
                    RatingBar ratingBar = (RatingBar)view;
                    ratingBar.setRating(cursor.getInt(rateIndex));
                    return true;
                }
                return false;
            }
        });

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>