Example demonstration of Android fragment

Fragment is a new concept in Android honeycomb 3.0. It is introduced in detail in how to use Android fragment. This article is mainly through examples to let you more intuitively understand the usage of fragment.

First, paste the screenshot of the running effect of the instance:

The left side of the rendering is a list, and the right side is the details of the list item.

Take a look at the layout file first:

XML / HTML code

The fragment tag and FrameLayout tag are used in the layout file. How to use Android fragment describes the two methods of embedding fragments in this example. It is seen from the layout file that there is a fragment tag, which is a method of use. The FrameLayout tag will become the second carrier view for loading fragments.

Take a look at the program implementation (COM. Fragment. Main. Titlesfragment):

Java code

Titlesfragment inherits from listfragment, a subclass of fragment. It uses a static array to fill the list, overrides onlistitemclick method, and showdetails method to display the details of listview item.

Java code

Here we use the second method of loading fragments introduced in Android fragment usage. Take a look at detailsfragment:

Java code

In detailsfragment, the newinstance (int index) method is used to generate the detailsfragment instance and accept integer parameters. The oncreateview method is overloaded to create the view.

This example is basically completed. It mainly introduces the use methods after 3.0. In fact, fragment is in sdk1 You can use it after 6. You need android-support-v4.0 to use it on 1.6 Jar package implementation. android-support-v4. Jar can be found in the SDK root directory \ extras \ Android \ compatibility \ v4.

The above is the data sorting of Android fragment. Continue to add relevant data in the future. Thank you for your support for this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>