Beginner Android's first exercises

Source: Internet
Author: User

Starter: personal blog, update & error correction & reply

Project source is here, because GitHub upload speed is too poor to upload to Oschina git hosting.


1. Project structure and technical points

Main Page
A fragment is a specific tab that uses fragmenttabhost,5 tags to correspond to one fragment. such as the "Blog" tab corresponding to the label page is blogfragment.

Blog tab page
Technical point: Use of the ListView
Technical point: Start an activity with intent
Technical point: Access the rest API using HttpClient and JSON packages
Blog Display page
Technical point: Using WebView to display Web pages, the HTML of the Web page is a programmed string

Favorites tab page
Favorite Display Page
Technical points: Use the WebView display page to specify the URL of the page to load

Book Sheet tab

Sticky Notes tab page
Technical point: Local database check and change operation
Technical point: Custom Adapter for ListView
Technical point: Relative layout
Sticky note form page
Technical points: Local database additions and deletions
Technical point: Call of the system service

Manage Tabs page
Technical point: The login page uses the local profile to save the user name password
Technical point: The table layout of the login page
Collection Management List page
Technical point: Access to the rest API's delete operation
Collection Management Form page
Technical point: Access to the rest API's add-on operation


2. Experience with technical points

The layout file is a simple XML file unrelated to the caller, representing a control tree, similar to the HTML fragment written in the <script type= "Text/plain" > tag, just a static text, passively waiting to be called. The caller will generate the control object tree in the program based on the tree structure declared in the XML text, and the control object tree is dealing with the user.
Layout is most commonly used in linear layout, you can display a good cross-screen resolution, vertical linear layout nested horizontal nesting layout, it is much like the page's div layout, first from top to bottom, then left to right. The table layout is much like a table layout in a Web page, ensuring alignment of the same column elements. The relative layout corresponds to the element that is detached from the document flow in the Web page, unlike the one that requires the control to be relative to a sibling node.

Fragmenttabhost implements the tab effect as the main page, each tab is fragment, and the new page that is displayed on the tab is activity. When the new page finishes working in code, or when the user clicks back on a new page, the new page is pushed back to the previous page, and if the closed page is a form page whose previous page is a list page, the list page needs to refresh the data when it is re-displayed, using the methods in the activity lifecycle.
Using the ListView Display List page, you can use the original adapter, each line displays a string, if you want to display richer information, you need to customize the adapter and custom inline layout style, adapter use the entity class is the layout parameter, In the response function, it is convenient to use subscript to get the entity to do everything you want to do.
Use WebView to display the Web page, you can specify the page content string, or specify a URL to let WebView directly load, the former like xxdiv.innerhtml= "XX", the latter is like xxiframe.src= "XX". By contrast, the former is more nuanced than the latter, and can be programmed to determine the contents of a string. Of course, the most subtle way to think about it is to use the Jsoup Library to control the DOM node, and finally generate an HTML string to load the WebView.

Local data, in addition to the most violent file reads and writes, local profiles and local databases are available choices. The former is suitable for storing some data similar to global variables, but is persistent (non-persistent public static, such as token at login, can also exist in global context), the latter is suitable for storing data of class and entity nature, because it can write SQL, The operation mode is infinitely similar to JDBC.
Remote data, the rest API access using the HttpClient and JSON library can be easily implemented, self-encapsulated a simple tool class, parameters very similar to Jquery.post methods, accept the path, parameters, successful failure two callback functions, Where failure means that the server returns a 4xx or 5xx status code instead of throwing exception in the program.
With regard to threads and callbacks, Java Web programmers may not be accustomed to modifying the page display after Ajax success, but in Android, the time-consuming operation such as accessing the API must be placed on a new thread, and the new thread does not allow the UI to be modified, and a handler must be declared on the main thread. The new thread calls the handler SendMessage, which can be seen as a callback function.


3. Self-study impressions and next week quests

in the Java Web Self-study, the use of servlet and JDBC to implement the deletion and modification of the day, to oneself is a qualitative change, which means that any subsequent progress is on this day based on the optimization and encapsulation. Because this day's results mean three points, one is equipped with the control of the UI, the second is to get through the channel with the database, and the third is to master the important native API. (most importantly, with a sense of control and confidence) , with this foundation, the future of the various libraries and frameworks will only become more and more simple.
So this week's progress is more satisfactory, although the page is still very ugly, data connection method has not been reconstructed to the best, many parameters and methods are not understood. But to achieve the strategic goal: the original API to realize the function of adding and deleting, as well as the most commonly used techniques for mapping. There is no third-party library in the project, and next week's task is to play with the most popular third-party libraries, using them and reading the source code, in turn enhancing the understanding of the underlying API. That's how I learned about Java Web.
Next weekend, there will be a meditation studio on GitHub app2.0 version of the source code, which contains the use of some good third-party libraries.

Last picture? Well, welcome to the Warring States chapter-

APK install package is downloaded here.

Long-term welcome project Cooperation Opportunity Introduction, project income 10% to reward introducer. Sina Weibo: @ Cold Mirror, qq:908789432.


Beginner Android's first exercises

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.