Android Knowledge Point Summary (3)

Source: Internet
Author: User
Tags sqlite database

Foreword: In the first two weeks we have made some basic framework of criminalintent application, we have learned some new knowledge--ui fragment and fragment in the process of compiling this part of basic stuff. These two new knowledge I already in the Android knowledge summary two inside has carried on the detailed elaboration, the need friend can go to this essay to check yo! (What are the shortcomings of the very welcome to point out that I will be in the later essays to improve?? OK, well, you might be bored, and we'll get to the point of today's essay ...

What we need to accomplish in these two weeks is the compilation of the three parts of the Criminalintent application's dialog box, the toolbar, and the SQLite database. It should be easy to see that these three parts are a core part of the Criminalintent application, so these three parts will certainly encounter a lot of knowledge that we have not been exposed to before. Next I will summarize some of the points of knowledge that I personally think are more important.

Criminalintent Application dialog box

The function of the dialog: we add the Criminalintent dialog to make it easier for the user to modify the crime record date.

dialog box operation: The user just click on the Date button in the Crimefragment, the application will pop up the dialog box, the specific operation process such as.

In this chapter of the dialog design, we mainly accomplish two parts: the Date dialog box and the fragment data transfer.

Date dialog box

During the completion of the date dialog we are still using fragment knowledge, and the approximate steps are as follows:

(1) Create dialogfragment

(2) Display dialogfragment

(3) Setting the contents of the dialog box

Fragment data transfer

The content of this section is mainly completed in two parts:

(1) Transfer the data to Datepickerfragment

To pass the crime date to datepickerfragment, you need to save it in Datepickerfragment's argument bundle. Creating and setting fragment argument is usually done in newinstance, so we'll add the Newinstance method to the Datepickerfragment, the method code is as follows:

Next we also add the Newinstance method in Crimefragment:   

The original crimefragment in the onclick datepckerfragment Dialog = new Datepickerfragment (); datepickerfragment Dialog =datepickerfragment.newintstance (Mcrime.getdate ());

finally we are going to get the date object and initialize the DatePicker, the implementation code is as follows:

(2) Return data to Crimefragment

First we set the target fragment, this is relatively simple to add a code in the Crimefragment:private static final int request_date = 0;

Next we add the Highlight Select Date button to update the code, such as:

Finally we set up a private method update, add this private method to the code crimefragment, code such as:

Tool bar

What the toolbar does: Toolbars can place menu options, provide app navigation, and help unify design styles and build brand image.

Toolbar style and how to use it: the toolbar gives the menu item of the crime record, and also has the function of upward, concrete as.

What we're going to do in this chapter is three parts: toolbars, menus, and hierarchical navigation.

Menu Toolbar

(1) First we want to add some strings in the Strings.xml (some are still not available, but it's okay to add them first), such as:

(2) Define the menu, in order to create a menu resource we need to write the following code in Fragment_crime_list.xml:

(3) Create a menu

First we will overwrite the Oncreateoptionsmenue method, implementing the menu defined in Fragment_crime_list.xml, with the following code:

Then call the Sethasoptionsmenu method to implement the menu callback, the code is as follows:

(4) Response menu item selection

First delete the code of random crime record in Crimelab;

Then add the Response menu item selection event in Crimelistfragment, as follows:

SQL database

Database role: persist data .

The completion process of the database:

(1) Define Schema

(2) Creating the initial database

(3) Modify Crimelab

(4) Writing to the database

Summary: The code of these several units let me understand that code writing needs to be very rigorous, to write the side of the run can not wait until writing a lot of testing, so if the wrong will be a headache. I hope you can develop a good habit of writing code side test!

Android Knowledge Point Summary (3)

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.