国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 個人理財工具五:顯示賬單明細 上

2019-12-12 05:29:43
字體:
來源:轉載
供稿:網友

前面我們已經將每個月的收支明細存入到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代碼

<?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="費用(元)"  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 參數中,指定這些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代碼

<?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="費用(元)"  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="當月收入:2009.33 支出:3000.87 小計:-1000.9"  android:textStyle="bold" android:layout_width="fill_parent" />  />    </LinearLayout>  </LinearLayout> </ScrollView> 

       這次我在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 個人理財工具五:顯示賬單明細 上

                       Android 個人理財工具四:添加賬單頁面 下

                       Android 個人理財工具三:添加賬單頁面 上

                       Android 個人理財工具二:使用SQLite實現啟動時初始化數據

                       Android 個人理財工具一:項目概述與啟動界面的實現

           以上就是關于顯示賬單明細的功能實現,后續繼續添加相關功能,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂溪县| 英德市| 霸州市| 施秉县| 漳平市| 绥中县| 陕西省| 花莲县| 高邮市| 衡阳市| 搜索| 依安县| 廊坊市| 宜川县| 德昌县| 进贤县| 隆尧县| 瑞丽市| 常宁市| 永登县| 双鸭山市| 屏东县| 宁津县| 科技| 淄博市| 英吉沙县| 佛坪县| 台中县| 诏安县| 云梦县| 朔州市| 疏附县| 仪征市| 诏安县| 祁门县| 探索| 常德市| 海伦市| 台江县| 东乌珠穆沁旗| 江川县|