Day 5, androidday

Source: Internet
Author: User

Day 5, androidday

Step 5-part 2 of Piglet's Android getting started

Activity Fragment: Fragment)

------ Reprinted with the source: coder-pig


This section introduces:

In part 1, we have analyzed the basic unit Activity of android in detail, and in part 2 we will explain

Activity Fragment (Fragment), which was initially designed to simplify the uidesign of large-screen mobile phones or tablets, but is now widely used

Ordinary mobile phones, such as Fragment + slideMenu, have many related examples on the Internet and have mastered the basic usage of Fragment.

It is easier to understand the code that uses Fragment to implement some effects!

Now, let's start this section!



This section describes the road map:


Body:


Fragment overview and lifecycle diagram:






Process for creating Fragment ① Static Loading Fragment:


Sample Code:

Divide the Activity into two Fragment

As follows:



The code is relatively simple and will not be listed one by one. Download the code as needed:Download reference code

Ps: Fragment sub-classes include:

Dialog Box: DialogFragment list: ListFragment

Option setting: PreferenceFragmentWebView interface: WebViewFragment


② Dynamic Fragment Loading



Code example: replace Fragment when switching between portrait and Landscape



This means that different fragment values are loaded when the screen is switched. We write the dynamic fragment Loading Method in the onCreate () method of the Activity.

When we switch between the horizontal and vertical screens, the Activity will be destroyed and loaded again!

The Code is also very simple. Download it by yourself:Code download




Interaction between Fragment and Activity






Fragment management and Fragment transactions



Code example: Click the list item on the left, and the corresponding details are displayed on the right:

As follows:

Portrait screen:



Horizontal screen:



This code is a bit difficult for beginners to understand: But it is already a simple example. Compared with the slide:

You have to think about it yourself! Download reference code:Code download




Ps: Fragment is an important part of android UI development,

This will be explained in conjunction with instances in the future! There will be further courses in the future! Thank you \ (^ o ^ )/






How can android get the date of 2nd 3 4 5 6 days?

Calendar cal = Calendar. getInstance ();

Cal. setTime (new Date ());
Cal. add (Calendar. DAY_OF_MONTH, 2); // 2nd days, x days, plus. If it is a negative number, it indicates the previous n days.

Date tomorrow = cal. getDate ();

For more information about how to get started with android development, see android beginners.

The secrets of android Application Development are quite good. I suggest you go to the bookstore and choose not to buy the app. If you buy the app to Dangdang or excellence, the discount should be 44.90; let me give you a link, and there are also those related to Dangdang, which are also good. You can look at the Android 2.0 game development practices with a DVD teaching disk, but it is about the code. This is expensive. Let's take a look. Here are some links for you: product.dangdang.com/...773186;
Www.amazon.cn/...3ugk_p;
Product.dangdang.com/..ct-0-e

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.