Android Apidemos Sample Resolution (2) Simpleadapter,listactivity,packagemanager

Source: Internet
Author: User

Once you have created the Apidemo project, you can analyze the code one by one, assuming that the reader has some knowledge of Android development or has read the concise Android development tutorials.

The first is to look at the main Activity:com.example.android.apis.ApiDemos of the Apidemo, the listactivity subclass of the main activity, which is used to list more than 200 instances of Apidemos, Instances are displayed at the classification level.

In Apidemos's OnCreate () code:

Setlistadapter New Simpleadapter (This, getData (path),
 Android. R.layout.simple_list_item_1, new string[] {"title"},     
 new int[] {Android. R.ID.TEXT1}));

Simpleadatper acts as a bridge between the data source GetData (path) and the UI listactivity, and its constructors are as follows:

Simpleadapter (context, list<? extendsmap<string,?>> data, int resource,string[] from, int[] to)

We know that listactivity can be used to display a list, and you can use the simpleadapter to better understand it when using a two-dimensional table. The data type of Simpleadapter is list<? Extendsmap<string, each item in the?>> list is a map object, equivalent to a row in a two-D table, which can have multiple columns, each column can have a name, a map<string,?> String, and the table's column name:

Each record in Apidemos displays only one column of "title". Android. R.layout.simple_list_item_1 for the layout resource ID used to display each record, Listactivity allows you to use a custom layout, which uses the Android system resources, Simple_list_item_ 1 is composed of a textview, whose ID is Text1.

New String [] {"title"} is an array of lists that need to be displayed, Apidemos only one column "title", if there are multiple columns: You can be new string[] {"title", "Field1", "Field2", "field3"}.

New int[] {Android. R.ID.TEXT1} Specifies the use of Android. R.layout.simple_list_item_1 the TextView with ID Text1 to display the "title" column. If you have more than one column, layout can define multiple view (not necessarily textview), and then specify the ID of the view that is displayed for each column.

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.