欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 個人理財(cái)工具五:顯示賬單明細(xì) 上

 更新時間:2016年08月30日 10:29:19   投稿:lqh  
本文主要介紹 Android 個人理財(cái)工具顯示賬單明細(xì),這里提供了示例代碼,和實(shí)現(xiàn)效果圖,幫助大家學(xué)習(xí)理解ListView的用法,有興趣的小伙伴可以參考下

前面我們已經(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)工具四:添加賬單頁面 下

                       Android 個人理財(cái)工具三:添加賬單頁面 上

                       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)功能,謝謝大家對本站的支持!

相關(guān)文章

最新評論