SQLite和ListView控件之间的数据格式 [英] Format data between SQLite and ListView

查看:164
本文介绍了SQLite和ListView控件之间的数据格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,必须有一个简单的解决这个...我有一个SQLite数据库,和我使用的标准SimpleCursorAdaptor把数据库置于一个ListView。没有问题存在。不过,我希望能够格式化一些数据在数据库中,在ListView之间。例如,我要除以100,在价格列中的所有数据(在数据库中的价格可能是5400,我希望它显示为54.00)。

I'm sure there must be a simple solution to this... I have a SQLite database, and I'm using the standard SimpleCursorAdaptor to put the database into a ListView. No problems there. However, I would like to be able to format some of the data in between the database and the ListView. For example, I want to divide all the data in the "price" column by 100 (in the database a price might be "5400", I want it displayed as "54.00").

推荐答案

使用的 SimpleCursorAdapter.ViewBinder

SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(..);
simpleCursorAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
        if(columnIndex == someColumnValue) {
                TextView text = (TextView) view;  // get your View
                text.setText(String.valueOf(cursor.getInt(1)/100));  //set some data
                return true;
        }
        return false;
    }
});

这篇关于SQLite和ListView控件之间的数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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