亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

前面我們已經(jīng)將每個月的收支明細存入到SQLite的數(shù)據(jù)表中,本文將實現(xiàn)從SQLite的數(shù)據(jù)表中取出這些數(shù)據(jù)顯示為賬單明細界面。

       下圖是最終的效果圖:

       在設(shè)計該界面時我考慮過好幾個方案。本來準備使用一個gridview,因為覺得名字很像我需要的東西??墒呛髞聿榱艘恍┵Y料,并且做了點實驗,發(fā)現(xiàn)和我想象的有些差距。于是采用了目前這種方式。使用Listview。

       這個界面布局實際上很簡單,就是上面一個表頭(Linearlayout),中間一個Listview,下面是一個腳注(Linearlayout)。

       如何實現(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); 

       這里我們只需要準備好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 參數(shù)中,指定這些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="當(dāng)月收入:2009.33 支出:3000.87 小計:-1000.9" 
 android:textStyle="bold" android:layout_width="fill_parent" /> 
 /> 
  
 </LinearLayout> 
 </LinearLayout> 
</ScrollView> 

       這次我在sqlite的sql上面遇到點麻煩,目前還沒搞定,就是我保存在數(shù)據(jù)庫中的費用是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,我估計可能是Adapter 里面的字符取出來用了getString的方法。

              系列文章:

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

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

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

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

                       Android 個人理財工具二:使用SQLite實現(xiàn)啟動時初始化數(shù)據(jù)

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

           以上就是關(guān)于顯示賬單明細的功能實現(xiàn),后續(xù)繼續(xù)添加相關(guān)功能,謝謝大家對本站的支持!

相關(guān)文章

  • Android 通過onDraw實現(xiàn)在View中繪圖操作的示例

    Android 通過onDraw實現(xiàn)在View中繪圖操作的示例

    以下是對Android通過onDraw實現(xiàn)在View中繪圖操作的示例代碼進行了詳細的分析介紹,需要的朋友可以過來參考下
    2013-07-07
  • Android對圖片Drawable實現(xiàn)變色示例代碼

    Android對圖片Drawable實現(xiàn)變色示例代碼

    這篇文章主要給大家介紹了關(guān)于Android對圖片Drawable實現(xiàn)變色的相關(guān)資料,文中通過示例代碼將實現(xiàn)的方法介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-08-08
  • Android實現(xiàn)屏幕手寫簽名

    Android實現(xiàn)屏幕手寫簽名

    這篇文章主要為大家詳細介紹了Android實現(xiàn)屏幕手寫簽名,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • android studio3.0.1無法啟動Gradle守護進程的解決方法

    android studio3.0.1無法啟動Gradle守護進程的解決方法

    這篇文章主要為大家詳細介紹了android studio3.0.1無法啟動Gradle守護進程的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android應(yīng)用中圖片瀏覽時實現(xiàn)自動切換功能的方法詳解

    Android應(yīng)用中圖片瀏覽時實現(xiàn)自動切換功能的方法詳解

    這篇文章主要介紹了Android應(yīng)用中圖片瀏覽時實現(xiàn)自動切換功能的方法,文中還講解了一個觸摸大圖進行圖片切換的深入功能,需要的朋友可以參考下
    2016-04-04
  • 解析Android橫豎屏切換的問題

    解析Android橫豎屏切換的問題

    本篇文章是對Android中橫豎屏切換的問題進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • Android啟動優(yōu)化之延時加載的步驟詳解

    Android啟動優(yōu)化之延時加載的步驟詳解

    這篇文章主要給大家介紹了關(guān)于Android啟動優(yōu)化之延時加載的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • Android通過原生APi獲取所在位置的經(jīng)緯度

    Android通過原生APi獲取所在位置的經(jīng)緯度

    本篇文章主要介紹了Android通過原生APi獲取所在位置的經(jīng)緯度,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • Android自定義RecyclerView實現(xiàn)不固定刻度的刻度尺

    Android自定義RecyclerView實現(xiàn)不固定刻度的刻度尺

    這篇文章主要為大家詳細介紹了Android自定義RecyclerView實現(xiàn)不固定刻度的刻度尺,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Android日期選擇控件使用詳解

    Android日期選擇控件使用詳解

    這篇文章主要為大家詳細介紹了Android日期選擇控件的使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08

最新評論