Android app personal application development (2) [sign-in function and accounting]

Source: Internet
Author: User

I 've been a little busy recently. I have to go to work tomorrow. I'm so angry. I am only free to post these two articles ···

The last time I talked about an idea, I first got the UI out.

Android provides several data storage methods:

1, shared preferences 2, SQLite Database

It is good to use sharedpreference for some simple small functions.

Next we will implement a sign-in function.

Let's take a look at the sign-in function:

This is mainly to go to the financial management interface to display a record similar to the prompt that operations have been performed today. The main purpose is to remind you whether the account has been added today, in addition, it is nice to have such a simple small function on the UI. Haha, I made two small pictures. One is "sign in" and the other is "not sign in". Then let's take a look at how the code is written.

First, define the basic fields of the Sharing priority data:

// Define the sharing priority data and basic fields
Private string my_rmbcost = "my_rmbcost ";

Private string todaytime = "todaytime ";

Then there is the sign-in processing function:

Time t = new time ();
T. settonow ();
Int lastmonth = T. Month + 1;
Final string STR = T. Year + "year" + lastmonth + "month" + T. monthday + "day ";


Final string nowtime = my_ RMB _data.getstring (todaytime, ""). tostring ();

If (nowtime. Equals (STR) = true)
{
TV _time.settext ("Date:" + nowtime + "checked in! ");
Bt_qiandao.setbackgroundresource (R. drawable. yqd );
}
Else
{
TV _time.settext ("Date:" + Str );
Bt_qiandao.setbackgroundresource (R. drawable. QD );
}

All code of the page:

Import Android. App. activity;
Import Android. content. intent;
Import Android. content. sharedpreferences;
Import Android. OS. Bundle;
Import Android. Text. format. time;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;
Import Android. widget. textview;
Import Android. widget. Toast;
Public class myrmbmanage extends activity {

// Define the sharing priority data and basic fields
Private string my_rmbcost = "my_rmbcost ";

Private string todaytime = "todaytime ";

Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. myrmbmanage );
Final button bt_qiandao = (button) findviewbyid (R. Id. bt_qiandao );
Final textview TV _time = (textview) findviewbyid (R. Id. TV _qiandaotime );
Final button bt_jz = (button) findviewbyid (R. Id. bt_jz );

// Read shared data
Sharedpreferences my_ RMB _data = getsharedpreferences (my_rmbcost, 0 );

Time t = new time ();
T. settonow ();
Int lastmonth = T. Month + 1;
Final string STR = T. Year + "year" + lastmonth + "month" + T. monthday + "day ";


Final string nowtime = my_ RMB _data.getstring (todaytime, ""). tostring ();

If (nowtime. Equals (STR) = true)
{
TV _time.settext ("Date:" + nowtime + "checked in! ");
Bt_qiandao.setbackgroundresource (R. drawable. yqd );
}
Else
{
TV _time.settext ("Date:" + Str );
Bt_qiandao.setbackgroundresource (R. drawable. QD );
}

// Button operation

// Sign-In Function
Bt_qiandao.setonclicklistener (New onclicklistener (){

Public void onclick (view v ){
// Todo auto-generated method stub
Sharedpreferences my_ RMB _data = getsharedpreferences (my_rmbcost, 0 );
If (my_ RMB _data.getstring (todaytime, ""). tostring (). Equals (STR) = true)
{
Toast. maketext (myrmbmanage. This, "you have signed in today! ", Toast. length_short). Show ();
}
Else
{
My_ RMB _data.edit ()
. Putstring (todaytime, STR)
. Commit ();
TV _time.settext ("Date:" + STR + "checked in! ");
Bt_qiandao.setbackgroundresource (R. drawable. yqd );
Toast. maketext (myrmbmanage. This, "check in successful! ", Toast. length_short). Show ();
}
}
});

// Accounting
Bt_jz.setonclicklistener (New onclicklistener (){

Public void onclick (view v ){
// Todo auto-generated method stub
Intent intent = new intent (myrmbmanage. This, todayspend. Class );
Startactivity (intent );
}
});

}
}

The sign-In function only uses sharedpreferences. If we have a large amount of data and need to use the method as needed, we need to use SQLite database. In the next section, we will layer these data-related things. After all, a well-organized code is what we want to see.

Then let's take a look at the accounting function UI:

The upper part also inherits the sign-in function, and lists the overhead forms that need to be entered in detail. Simple and Easy to use is what we want. I just want to record my financial accounting records with one click when I want to keep my account. In the lower half, the overhead information of today and yesterday is displayed. In this way, the opening of yesterday and today is clear, haha. The most important feature is the drop-down list. We need the drop-down list to display the date of the account that has been added this month, and assign values to the form after selection for modification and editing. It can also query the account overhead for any day. Then the entire UI basically has the expected functions. In the next section, we will implement this function.

The next section on SQLite database data access will be posted. I hope you can communicate with each other. If there is any improvement, you can learn from each other.

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.