Android ApiDemos example resolution (114): Views-& gt; Expandable Lists-& am

Source: Internet
Author: User

This example describes how to use Map-based data as the data source of the Expandable List.

Group and Child are defined as follows:

[Java]
List <Map <String, String> groupData
= New ArrayList <Map <String, String> ();
List <Map <String, String> childData
= New ArrayList <List <Map <String, String >>> ();

List <Map <String, String> groupData
= New ArrayList <Map <String, String> ();
List <Map <String, String> childData
= New ArrayList <List <Map <String, String >>> ();

 

It looks a bit complicated :-). Map <String, String> is similar to the Hash table. It can be regarded as a row of the database table, with the column name as the keyword. For example, the data of a row in this example is

 

In this example, 20 sub-elements are defined for groupData, from group 0 to group 19. For each group, 15 sub-elements are defined, from child 0 to child 14.

Each element also has the following values:

 

With groupdata and childdata, you can call the SimpleExpandableListAdapter constructor:

[Java]
// Set up our adapter
MAdapter = new SimpleExpandableListAdapter (
This,
GroupData,
Android. R. layout. simple_expandable_list_item_1,
New String [] {NAME, IS_EVEN },
New int [] {android. R. id. text1, android. R. id. text2 },
ChildData,
Android. R. layout. simple_expandable_list_item_2,
New String [] {NAME, IS_EVEN },
New int [] {android. R. id. text1, android. R. id. text2}
);

// Set up our adapter
MAdapter = new SimpleExpandableListAdapter (
This,
GroupData,
Android. R. layout. simple_expandable_list_item_1,
New String [] {NAME, IS_EVEN },
New int [] {android. R. id. text1, android. R. id. text2 },
ChildData,
Android. R. layout. simple_expandable_list_item_2,
New String [] {NAME, IS_EVEN },
New int [] {android. R. id. text1, android. R. id. text2}
);
Public SimpleExpandableListAdapter (Context context,
List <? Extends Map <String,?> GroupData,
Int groupLayout, String [] groupFrom,
Int [] groupTo,
List <? Extends List <? Extends Map <String,? >>> ChildData,
Int childLayout,
String [] childFrom, int [] childTo)

Context: context object. You can use activity.
Groupdata: group data source
GroupLayout: Group Layout resource ID. In this example, the system resource simple_expandable_list_item_2 is used.
Childdata: child Data Source
ChildLayout: child Layout resource ID. In this example, the system resource simple_expandable_list_item_2 is used.
GroupFrom: array of group column names to be displayed
GroupTo: View id corresponding to the columns of each group
ChildrenFrom: name of the group members to be displayed
ChildrenTo: id of the View corresponding to the columns of each group member.
Simple_expandable_list_item_1.xml and simple_expandable_list_item_2.xml can be found in the http://www.netmite.com/android/mydroid/frameworks/base/core/res/res/layout/

Simple_expandable_list_item_1 defines a text box id as text1. In the original example, simple_expandable_list_item_1 is used to display the group. The corresponding IS_EVEN uses text2 to display the View id. Therefore, only Group xx is displayed. After the preceding modification, simple_expandable_list_item_2, NAME, and IS_EVEN are used for both group and child:

 

 

Author: mapdigit

 

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.