前面我们已经将每个月的收支明细存入到SQLite的数据表中,本文将实现从SQLite的数据表中取出这些数据显示为账单明细界面。

下图是最终的效果图:

在设计该界面时我考虑过好几个方案。本来准备使用一个gridview,因为觉得名字很像我需要的东西。可是后来查了一些资料,并且做了点实验,发现和我想象的有些差距。于是采用了目前这种方式。使用Listview。

这个界面布局实际上很简单,就是上面一个表头(Linearlayout),中间一个Listview,下面是一个脚注(Linearlayout)。

如何实现listview其中内容?这个主要就是要理解Adapter的用法。

SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)

Java代码

String[] from=new String[] {"rowid","name", "fee","sdate","desc" };

int[] to=new int[] { R.id.item1, R.id.item2,R.id.item3,R.id.item4,R.id.item5 };

SimpleCursorAdapter mAdapter=new SimpleCursorAdapter(this,R.layout.grid_items, cur,from, to);

lv.setAdapter(mAdapter);

这里我们只需要准备好view的样式和cursor就可以了。

例如本例中的

R.layout.grid_items是

XML/HTML代码

android:orientation="horizontal" android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="wrap_content" android:width="20dip"

/>

android:layout_height="fill_parent"

android:text="账目"

android:width="60dip" android:layout_width="wrap_content"/>

/>

android:text="费用(元)"

android:textSize="14dip" android:width="60dip" android:layout_width="wrap_content"

android:layout_height="fill_parent" android:textStyle="bold|italic"

/>

android:layout_height="fill_parent"

android:text="日期"

android:width="80dip"

android:layout_width="wrap_content"

/>

android:layout_height="fill_parent"

android:text="备注"

android:width="100dip" android:layout_width="wrap_content"

/>

在Adapter中的to 参数中,指定这些TextView使用那些Cursor的值。

我的cursor就是含有这些字段"rowid","name","fee","sdate","desc"。

准备好这些,使用lv.setAdapter(mAdapter)方法就可以绑定了。

下面给出具体代码文件:

Grid_bills.java

Java代码

package com.cola.ui;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import android.app.Activity;

import android.database.Cursor;

import android.os.Bundle;

import android.util.Log;

import android.view.KeyEvent;

import android.view.View;

import android.widget.AbsoluteLayout;

import android.widget.EditText;

import android.widget.GridView;

import android.widget.LinearLayout;

import android.widget.ListView;

import android.widget.SimpleCursorAdapter;

import android.widget.TextView;

public class Grid_bills extends Activity {

BilldbHelper billdb;

View sv;

EditText edit;

AbsoluteLayout alayout;

int a=10,b=10;

GridView grd;

TextView total;

protected GridView listHands = null ;

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setTitle("ColaBox-账单明细(2008-11月)");

setContentView( R.layout.grid_bills) ;

billdb = new BilldbHelper(this);

Cursor cur=billdb.getBills();

ListView lv=(ListView)findViewById(R.id.listview);

String[] from=new String[] {"rowid","name", "fee","sdate","desc" };

int[] to=new int[] { R.id.item1, R.id.item2,R.id.item3,R.id.item4,R.id.item5 };

SimpleCursorAdapter mAdapter=new SimpleCursorAdapter(this,R.layout.grid_items, cur,from, to);

lv.setAdapter(mAdapter);

//getBillsTotal

total=(TextView)findViewById(R.id.totalitem);

total.setText(billdb.getBillsTotal("2008-11"));

}

grid_item.xml

XML/HTML代码

android:orientation="vertical"

android:layout_height="fill_parent" android:layout_width="fill_parent">

android:id="@+id/LinearLayout01"

xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">

android:background="#ffCded8b" android:layout_height="fill_parent" android:layout_width="fill_parent" android:focusable="true" android:clickable="true" android:focusableInTouchMode="true" android:keepScreenOn="true">

android:layout_width="wrap_content" android:width="20dip"

/>

android:layout_height="fill_parent"

android:text="账目"

android:textStyle="bold" android:width="60dip" android:layout_width="wrap_content"/>

/>

android:text="费用(元)"

android:textSize="14dip" android:textStyle="bold" android:width="60dip" android:layout_width="wrap_content"

android:layout_height="fill_parent"/>

android:layout_height="fill_parent"

android:text="日期"

android:textSize="14dip" android:textStyle="bold" android:width="80dip" android:layout_width="wrap_content"

/>

android:layout_height="fill_parent"

android:text="备注"

android:textSize="14dip" android:textStyle="bold" android:width="100dip" android:layout_width="wrap_content"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content" android:background="#ffCded8b">

android:layout_height="fill_parent"

android:text="当月收入:2009.33 支出:3000.87 小计:-1000.9"

android:textStyle="bold" android:layout_width="fill_parent" />

/>

这次我在sqlite的sql上面遇到点麻烦,目前还没搞定,就是我保存在数据库中的费用是int型,分为单位。我从数据库中取出来是 select fee/100 from bills ;但是显示的却是取整后的数值。

不知道正确语法应该是什么样子,后面我想拼成字符显示应该可以,我就试了 select fee/100||'' from bills;,这样就可以在listview上面输出小数。可是我发现999999.99/100 输出却是1000000。我在adb shell里面查询还是999999.99,到了listview时就变成了1000000,我估计可能是Adapter 里面的字符取出来用了getString的方法。

系列文章:

以上就是关于显示账单明细的功能实现,后续继续添加相关功能,谢谢大家对本站的支持!

android 实例-个人理财工具 之六,Android 个人理财工具五:显示账单明细 上相关推荐

  1. [Android实例] 最全的Android开发资源整理--进阶必备

    本帖最后由 一切随枫 于 2014-6-9 12:08 编辑 原文链接: http://stormzhang.github.io/android/2014/06/05/android-awesome- ...

  2. android实例教程_改造Android示例教程

    android实例教程 Welcome to Retrofit Android Example Tutorial. Today we'll use the Retrofit library devel ...

  3. android 实例源码解释,Android Handler 原理分析及实例代码

    Android Handler 原理分析 Handler一个让无数android开发者头疼的东西,希望我今天这边文章能为您彻底根治这个问题 今天就为大家详细剖析下Handler的原理 Handler使 ...

  4. android 实例-个人理财工具,Android 个人理财工具六:显示账单明细 下

    上一节的显示账单明细 上中,账单明细的显示已经基本实现,本文主要整理下代码,实现此窗口的查询和删除功能:按下Menu菜单时弹出选择月份的窗口,可选择明细的月份:在ListView上长按可弹出确认删除的 ...

  5. Android 实例-个人理财工具 之五 账单明细显示A

    关键字:android sdk 1.0 custom listview 前面我们已经实现了把每月的收支明细,录入到了表中,现在就是要实现把这些数据从sqlite的数据表中取出来展现. 上图就是最后的界 ...

  6. 【Android 内存优化】使用 Memory Analyzer ( MAT ) 工具分析内存 ( MAT 工具使用 | 最大对象 | 类实例个数 | 引用与被引用 | GC Roots 最短链 )

    文章目录 一. 内存中最大的对象 二. 查看每个类的对象实例的个数 三. 查看对象的引用与被引用 四. 查看对象到 GC Roots 的最短距离 1. 选择 Merge Shortest Paths ...

  7. android aidl工具,【Android】AIDL介绍和实例讲解

    前言 为使应用程序之间能够彼此通信,Android提供了IPC (Inter Process Communication,进程间通信)的一种独特实现: AIDL (Android Interface ...

  8. 【安卓学习之开发工具】 Android 学习-- 下载过的一些项目

    █ [安卓学习之开发工具] Android 学习-- 下载过的一些项目 █ 相关文章: ● [安卓学习之常见问题] app维护可能遇到的问题 ● [IOS学习之常见问题] app维护可能遇到的问题 ● ...

  9. Android Studio - HPROF文件查看和分析工具

    Android Studio - HPROF文件查看和分析工具 Android Studio 翻译的官方文章 原文链接 当你在Android Studio中使用Android Monitor里的Mem ...

最新文章

  1. 怎么成为优秀的软件模型设计者?
  2. Docke的WEB管理工具
  3. JavaScript中整型数据使用
  4. mysql字符调整_mysql字符集调整
  5. jquery-uploadifyv3.2.1 文件上传插件 学习
  6. 设计模式 工厂方法_使用工厂方法模式设计最佳实践
  7. [react-router] react的路由和普通路由有什么区别?
  8. Maven常用命令 - 构建反应堆中指定模块
  9. 黑苹果efi制作_黑苹果微星B450AMD完美方案分享包括EFI制作工具及教程
  10. 威纶通触摸屏与2台台达温控器modbus rtu 通讯程序
  11. 《区块链开源技术需求调研报告》拍了拍你
  12. Flutter入门进阶之旅(六)Layout Widget
  13. 「数据架构」数据模型,数据字典,数据库模式 和ERD的比较
  14. CAP定理以及BASE定理详解
  15. [Android]进程通信Andromeda框架
  16. 调和数,1加二分之一加三分之一加到 n 分之一
  17. 一文看懂:网址,URL,域名,IP地址,DNS,域名解析
  18. 删除计算机自带的游戏软件,win10系统删除自带游戏的处理办法
  19. 电脑新加内存条后 游戏崩溃 浏览器卡死 电脑蓝屏
  20. Unity开发之-Unity入门简介(近万字攻略)

热门文章

  1. 图像处理去噪点(中值滤波)java
  2. 深度学习MEMC插帧论文列表paper list
  3. 2021/11/11
  4. dnp服务器未响应,360浏览器没响应怎么办 360浏览器未响应死机解决方法分享
  5. Android KTX简介
  6. 张驰课堂:2022年CAQ中质协六西格玛考试时间通知
  7. NASA-VIIRS夜间灯光VNP46A2产品及批量下载
  8. python学习与疑问_1
  9. java安装jdk时显示系统管理员设置了系统策略,禁止进行此安装
  10. java(11):tomcat简介与使用(上)