前面我们已经将每个月的收支明细存入到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. 关系管理系统:js代码生成select的出生日期
  2. 陆奇宣布卸任COO后首度露面,将担任李彦宏的个人顾问
  3. Kali-Linux虚拟机安装提示
  4. 【朝夕技术专刊】Core3.1WebApi_Filter详解
  5. 继Science发文后,Nature也发文评论曹雪涛“误用图片”调查结果
  6. 产业数字化升级进入深化期,腾讯智慧出行释放“数字底座”核心能力
  7. android 视频录制小例子,android 录制视频实例 VideoRecordDemo
  8. python判断一个数是否是质数
  9. 讯飞输入法更新10.0版本 上线全新A.I.语音输入引擎
  10. 云计算网络产品sdn以及VxLAN技术浅析
  11. 坐标3度带与6度带的知识(转载)
  12. dfs文件服务器详解,DFS文件服务器详解
  13. 手机网站开发的经验总结
  14. 3Dmax Bones骨骼学习记录一
  15. Unity3D网络游戏实战——通用服务器框架
  16. VC++实现电脑睡眠/休眠/锁定/关闭屏幕
  17. STM32H743,基于LL库实现adc采样(ADC+DMA+TIM)
  18. 【mud】文字mud游戏的魅力(龟跑比赛)
  19. 音响店VCD零售/出租系统(软件定义)
  20. 26对称矩阵及正定性

热门文章

  1. 什么是cms,了解一下。
  2. 学习Java好还是python好?
  3. 新能源电动汽车虚拟仿真教学软件 - 新能源汽车vr实训
  4. heartbeat v2 + lvs-DR实现Director的高可用
  5. GBASE南大通用为行业信创发展提速 亮相全国信创与人工智能发展博士后论坛
  6. 微型计算机可以作为提供CPU,谁知道计算机应和基础练习题答案?
  7. 华科C++大一MOOC
  8. FTP,NFS,SAMBA的比较
  9. 高频、射频、微波的区别
  10. kyo酱的博客--回溯法