Android 個人理財(cái)工具五:顯示賬單明細(xì) 上
前面我們已經(jīng)將每個月的收支明細(xì)存入到SQLite的數(shù)據(jù)表中,本文將實(shí)現(xiàn)從SQLite的數(shù)據(jù)表中取出這些數(shù)據(jù)顯示為賬單明細(xì)界面。
下圖是最終的效果圖:
在設(shè)計(jì)該界面時我考慮過好幾個方案。本來準(zhǔn)備使用一個gridview,因?yàn)橛X得名字很像我需要的東西??墒呛髞聿榱艘恍┵Y料,并且做了點(diǎn)實(shí)驗(yàn),發(fā)現(xiàn)和我想象的有些差距。于是采用了目前這種方式。使用Listview。
這個界面布局實(shí)際上很簡單,就是上面一個表頭(Linearlayout),中間一個Listview,下面是一個腳注(Linearlayout)。
如何實(shí)現(xiàn)listview其中內(nèi)容?這個主要就是要理解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);
這里我們只需要準(zhǔn)備好view的樣式和cursor就可以了。
例如本例中的
R.layout.grid_items是
XML/HTML代碼
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/item1" android:layout_height="fill_parent" android:layout_width="wrap_content" android:width="20dip" /> <TextView android:id="@+id/item2" android:layout_height="fill_parent" android:text="賬目" android:width="60dip" android:layout_width="wrap_content"/> /> <TextView android:id="@+id/item3" android:text="費(fèi)用(元)" android:textSize="14dip" android:width="60dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textStyle="bold|italic" /> <TextView android:id="@+id/item4" android:layout_height="fill_parent" android:text="日期" android:width="80dip" android:layout_width="wrap_content" /> <TextView android:id="@+id/item5" android:layout_height="fill_parent" android:text="備注" android:width="100dip" android:layout_width="wrap_content" /> </LinearLayout>
在Adapter中的to 參數(shù)中,指定這些TextView使用那些Cursor的值。
我的cursor就是含有這些字段"rowid","name","fee","sdate","desc"。
準(zhǔn)備好這些,使用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-賬單明細(xì)(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代碼
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"> <LinearLayout 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"> <LinearLayout android:id="@+id/layouthead" 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"> <TextView android:id="@+id/item1" android:layout_height="fill_parent" android:layout_width="wrap_content" android:width="20dip" /> <TextView android:id="@+id/item2" android:layout_height="fill_parent" android:text="賬目" android:textStyle="bold" android:width="60dip" android:layout_width="wrap_content"/> /> <TextView android:id="@+id/item3" android:text="費(fèi)用(元)" android:textSize="14dip" android:textStyle="bold" android:width="60dip" android:layout_width="wrap_content" android:layout_height="fill_parent"/> <TextView android:id="@+id/item4" android:layout_height="fill_parent" android:text="日期" android:textSize="14dip" android:textStyle="bold" android:width="80dip" android:layout_width="wrap_content" /> <TextView android:id="@+id/item5" android:layout_height="fill_parent" android:text="備注" android:textSize="14dip" android:textStyle="bold" android:width="100dip" android:layout_width="wrap_content" /> </LinearLayout> <View android:layout_width="fill_parent" android:layout_height="1dip" android:background="?android:attr/listDivider"/> <LinearLayout android:id="@+id/layout" android:layout_width="wrap_content" android:layout_height="fill_parent" android:minHeight="372dip"> <ListView android:id="@+id/listview" android:layout_height="fill_parent" android:layout_width="fill_parent"></ListView> </LinearLayout> <LinearLayout android:id="@+id/layoutfoot" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ffCded8b"> <TextView android:id="@+id/totalitem" android:layout_height="fill_parent" android:text="當(dāng)月收入:2009.33 支出:3000.87 小計(jì):-1000.9" android:textStyle="bold" android:layout_width="fill_parent" /> /> </LinearLayout> </LinearLayout> </ScrollView>
這次我在sqlite的sql上面遇到點(diǎn)麻煩,目前還沒搞定,就是我保存在數(shù)據(jù)庫中的費(fèi)用是int型,分為單位。我從數(shù)據(jù)庫中取出來是 select fee/100 from bills ;但是顯示的卻是取整后的數(shù)值。
不知道正確語法應(yīng)該是什么樣子,后面我想拼成字符顯示應(yīng)該可以,我就試了 select fee/100||'' from bills;,這樣就可以在listview上面輸出小數(shù)。可是我發(fā)現(xiàn)999999.99/100 輸出卻是1000000。我在adb shell里面查詢還是999999.99,到了listview時就變成了1000000,我估計(jì)可能是Adapter 里面的字符取出來用了getString的方法。
系列文章:
Android 個人理財(cái)工具六:顯示賬單明細(xì) 下
Android 個人理財(cái)工具五:顯示賬單明細(xì) 上
Android 個人理財(cái)工具二:使用SQLite實(shí)現(xiàn)啟動時初始化數(shù)據(jù)
Android 個人理財(cái)工具一:項(xiàng)目概述與啟動界面的實(shí)現(xiàn)
以上就是關(guān)于顯示賬單明細(xì)的功能實(shí)現(xiàn),后續(xù)繼續(xù)添加相關(guān)功能,謝謝大家對本站的支持!
- Android 個人理財(cái)工具六:顯示賬單明細(xì) 下
- Android 個人理財(cái)工具四:添加賬單頁面 下
- Android 個人理財(cái)工具三:添加賬單頁面 上
- Android 個人理財(cái)工具二:使用SQLite實(shí)現(xiàn)啟動時初始化數(shù)據(jù)
- Android 個人理財(cái)工具一:項(xiàng)目概述與啟動界面的實(shí)現(xiàn)
- Android 錢包支付之輸入支付密碼的實(shí)現(xiàn)步驟
- Android 高仿微信轉(zhuǎn)賬金錢輸入框規(guī)則
- Android快速實(shí)現(xiàn)一個財(cái)務(wù)APP程序詳解
相關(guān)文章
Android 通過onDraw實(shí)現(xiàn)在View中繪圖操作的示例
以下是對Android通過onDraw實(shí)現(xiàn)在View中繪圖操作的示例代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過來參考下2013-07-07Android對圖片Drawable實(shí)現(xiàn)變色示例代碼
這篇文章主要給大家介紹了關(guān)于Android對圖片Drawable實(shí)現(xiàn)變色的相關(guān)資料,文中通過示例代碼將實(shí)現(xiàn)的方法介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-08-08android studio3.0.1無法啟動Gradle守護(hù)進(jìn)程的解決方法
這篇文章主要為大家詳細(xì)介紹了android studio3.0.1無法啟動Gradle守護(hù)進(jìn)程的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Android應(yīng)用中圖片瀏覽時實(shí)現(xiàn)自動切換功能的方法詳解
這篇文章主要介紹了Android應(yīng)用中圖片瀏覽時實(shí)現(xiàn)自動切換功能的方法,文中還講解了一個觸摸大圖進(jìn)行圖片切換的深入功能,需要的朋友可以參考下2016-04-04Android通過原生APi獲取所在位置的經(jīng)緯度
本篇文章主要介紹了Android通過原生APi獲取所在位置的經(jīng)緯度,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07Android自定義RecyclerView實(shí)現(xiàn)不固定刻度的刻度尺
這篇文章主要為大家詳細(xì)介紹了Android自定義RecyclerView實(shí)現(xiàn)不固定刻度的刻度尺,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07