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

來源:果殼範文吧 7.37K

前面我們已經將每個月的收支明細存入到SQLite的資料表中,本文將實現從SQLite的資料表中取出這些資料顯示為賬單明細介面。

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

下圖是最終的效果圖:

設計該介面時我考慮過好幾個方案。本來準備使用一個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[] { 1, 2,3,4,5 }; SimpleCursorAdapter mAdapter=new SimpleCursorAdapter(this,_items, cur,from, to); dapter(mAdapter);

這裡我們只需要準備好view的`樣式和cursor就可以了。

例如本例中的

_items是

XML/HTML程式碼

<"1.0" encoding="utf-8">/>

在Adapter中的to 引數中,指定這些TextView使用那些Cursor的值。

我的cursor就是含有這些欄位"rowid","name","fee","sdate","desc"。

準備好這些,使用dapter(mAdapter)方法就可以綁定了。

下面給出具體程式碼檔案:

Grid_

Java程式碼

package ; import yList; import Map; import ; import ; import vity; import or; import le; import ; import vent; import ; import luteLayout; import Text; import View; import arLayout; import View; import leCursorAdapter; import View; 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) { eate(icicle); setTitle("ColaBox-賬單明細(2008-11月)"); setContentView( _bills) ; billdb = new BilldbHelper(this); Cursor cur=ills(); ListView lv=(ListView)findViewById(view); String[] from=new String[] {"rowid","name", "fee","sdate","desc" }; int[] to=new int[] { 1, 2,3,4,5 }; SimpleCursorAdapter mAdapter=new SimpleCursorAdapter(this,_items, cur,from, to); dapter(mAdapter); //getBillsTotal total=(TextView)findViewById(litem); ext(illsTotal("2008-11")); }

grid_

XML/HTML程式碼

<"1.0" encoding="utf-8">/>/>

這次我在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的方法。

熱門標籤