Android Personal Finance tool five: Show billing details on _android

Source: Internet
Author: User
Tags sqlite

We have previously deposited the monthly revenue and expenditure details into the SQLite datasheet, this article will be implemented from the SQLite datasheet to remove the data displayed as the billing detail interface.

The following diagram is the final effect chart:

I have considered several scenarios when designing this interface. I was going to use a GridView because I thought the name was very much like what I needed. But then I checked some information, and did some experiments, and found some gaps with my imagination. So the current approach was adopted. Use ListView.

The interface layout is actually very simple, which is the top table header (LinearLayout), the middle one ListView, and the following is a footnote (linearlayout).

How do I implement ListView content? This is mainly to understand the use of adapter.

Simplecursoradapter (context context, int layout, Cursor C, string[] from, int[] to)

Java code

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); 

Here we just need to prepare the view style and cursor.

For example, in this example

R.layout.grid_items is

xml/html Code

<?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= "Accounts" android:width= "60dip" android:layout_width= "wrap_content"/>/> <textview android:id= "@+id/item3" and roid:text= "fee (yuan)" 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:layo ut_height= "Fill_parent" android:text= "date" android:width= "80dip" android:layout_width= "wrap_content"/> <T Extview android:id= "@+id/item5" Android:layout_height= "Fill_parent" android:text= "Memo" android:width= "100dip" android:layout_width= "wrap_content"/> </Linea 
 Rlayout>

In the to argument in adapter, specify the values that these textview use for those cursor.

My cursor is to include these fields "rowID", "name", "fee", "sdate", "desc".

When you're ready, use the Lv.setadapter (Madapter) method to bind.

The specific code files are given below:

Grid_bills.java

Java code

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-Billing details (2 August-November)"); 
 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 Code

<?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= "accounts" android:textstyle= "bold" android:width="60dip" android:layout_width= "wrap_content"/>/> <textview android:id= "@+id/item3" android:text= "fee (yuan)" a Ndroid: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= "Date" 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= "Remarks" Andro Id: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" &GT <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=" month Revenue: 2009.33 expenditure: 3000.87 subtotal: -1000.9 "Android:textstyle = "Bold" android:layout_width= "Fill_parent"/>/> </LinearLayout> </LinearLayout> </scrollvi 
 Ew>

This time I encountered a bit of trouble in SQLite's SQL, which is not yet fixed, is that I saved in the database of the cost is int type, divided into units. I took it out of the database as a select fee/100 from bills, but it was displayed with an integer value.

Do not know what the correct grammar should look like, I want to spell a character display should be OK, I tried the Select Fee/100| | ' From bills, so that you can output decimals on the ListView. But I found that the 999999.99/100 output was 1000000. I am in the adb shell query or 999999.99, when the ListView into a 1000000, I think it may be adapter inside the characters out of the GetString method.

Series of articles:

Android Personal Finance Tool Six: Show billing details below

Android Personal Finance tool five: show billing details

Android Personal Finance Tools Four: Add Bill page below

Android Personal Finance Tool Three: Add Bill page

Android Personal Finance Tools two: Use SQLite to implement initialization data at startup

Android Personal Finance Tools One: Project overview and implementation of the launch interface

The above is about display billing details of the function to achieve, follow-up continue to add related functions, thank you for your support of this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.