An explanation of the use of Android Expandablelistview

Source: Internet
Author: User

Expandablelistview (extensible ListView)

Expandablelistvivew is a sub-class of the ListView, which is extended on the basis of the normal ListView, which divides the list items in the application into groups, each of which can contain multiple list items. The usage of expandablelistvivew is very similar to the usage of the normal ListView, except that the list items displayed by Expandablelistvivew should be provided by Expandableadapter.

Three ways to implement Expandableadapter

One is to extend the Baseexpandablelistadpter implementation expandableadapter.

The second is to use Simpleexpandablelistadpater to wrap two list sets into a expandableadapter

The third is to use Simplecursortreeadapter to wrap the data in the cursor into Simplecurotreeadapter

XML attributes supported for Expandablelistvivew

XML Attributes

related Method

< Span style= "FONT-SIZE:16PX;" > description

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

android:childdivider

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

android:childindicator

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

android:childindicatorleft

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

android:childindicatorright

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

android:groupindicator

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

android:indicatorleft

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

&NBSP;

Android:indicatorright

The right constraint position of the Group list item indicator ⑦

Note:

① Note: The picture will not be fully displayed, the sub-ionic list item is a straight line

② Note: can be a picture

③ Note: That is, starting from the left 0 position counting, for example, suppose the indicator is an icon, given this property value is

3dip, the icon is displayed starting at 3dip from the left end.

④ Note: Indicates where the right end ends

⑤ Note: Can be a picture.

⑥ Note: Indicates where the left position begins.

⑦ Note: Indicates where the right end ends.

Adapter that are generally applicable to Expandablelistview inherit the Baseexpandablelistadapter class, and the two most important methods of Getgroupview and Getchildview must be overloaded.

When extending Baseexpandablelistadapter, the key is to implement the following four methods:

public abstract Viewgetchildview (int groupposition, Intchildposition, Boolean islastchild, Viewconvertview, ViewGroup Parent

Gets the view that displays the data for a given sub-location for the specified grouping.

Parameters

Groupposition contains the grouped locations to get the child views.

Childposition the position of the grouped neutron view (the view to return).

Islastchild whether the view is the last view in the group.

Convertview if possible, reuse the old view object. You should ensure that the view object is non-empty and is the appropriate type before you use it. If the object cannot be converted to a view that displays the data correctly, the method creates a new view. Not guaranteed to use previously by Getchildview (int, Int,boolean, view, ViewGroup) created views.

The parent view that the view ultimately belongs to.

Return

Specifies the corresponding child view of the location.

public abstract Intgetchildrencount (int groupposition)

Gets the number of child elements for the specified grouping.

Parameters

Groupposition the grouping position to get the number of child elements.

Return

Specifies the number of child elements to group.

public abstract Viewgetgroupview (int groupposition, booleanisexpanded, View Convertview, viewgroupparent)

Gets the view that is used to display the given grouping. This method returns only the grouped view objects, and you need to call Getchildview (int, int, Boolean, view, ViewGroup) to get the view object of the child element.

Parameters

Groupposition determines which view group position to return.

IsExpanded whether the group is expanded or is in a closed state.

Convertview if possible, reuse the old view object. You should ensure that the view object is non-empty and is the appropriate type before you use it. If the object cannot be converted to a view that displays the data correctly, the method creates a new view. Not guaranteed to use previously by Getgroupview (int, Boolean,view, ViewGroup) creates a view.

The parent view that the view ultimately belongs to.

Return

Specifies the appropriate group view for the location.

public abstract Intgetgroupcount ()

Gets the number of groups.

Return

The number of groups.

The other methods of overloading Baseexpandablelistadapter are as follows:

Public abstract Object getchild (int groupposition, int childposition)

Gets the data associated with the specified grouping, specified sub-item.

Parameters

Groupposition contains the location of the grouped sub-views.

Childposition the position of the child view in the specified grouping.

Return

The data associated with the child view.

Public abstract long Getchildid (int groupposition, intchildposition)

Gets the ID of the given child view in the given grouping. The group ID must be unique within the group. Must be different from all other IDs (group and subproject IDs).

Parameters

Groupposition contains the location of the grouped sub-views.

Childposition the location of the child view in the specified grouping to get the ID.

Return

The ID associated with the child view.

Public abstract Longgetcombinedchildid (long groupId, long childID)

Gets the ID of the list that uniquely identifies the child entry, including the group ID and the child entry ID. The extensible list requires that each entry (grouping entries and sub-entries) have an ID that uniquely identifies the sub-entries and grouping entries in the list. This method returns a unique identification ID based on the given child entry ID and the group entry ID. Also, if Hasstablei DS () is true, the ID returned by the function must be fixed.

Parameters

GroupId contains the group entry ID for the child entry ID.

The ID of the childID child entry.

Return

The ID of the child entry can be uniquely identified in all grouping entries and sub-entries (possibly fixed).

Public abstract longgetcombinedgroupid (long groupId)

Gets the ID of the list that uniquely identifies the child entry, including the group ID and the child entry ID. The extensible list requires that each entry (grouping entries and sub-entries) have an ID that uniquely identifies the sub-entries and grouping entries in the list. This method returns a unique identification ID based on the given child entry ID and the group entry ID. Also, if Hasstablei DS () is true, the ID returned by the function must be fixed.

Parameters

GroupId the group entry ID.

Return

The ID of the grouping entry can be uniquely identified in all grouping entries and sub-entries (possibly fixed).

Public abstract Object getgroup (int groupposition)

Gets the data associated with the given grouping.

Parameters

Groupposition the location of the grouping.

Return

Specifies the grouped data.

Public abstract long Getgroupid (int groupposition)

Gets the ID of the specified grouping. The group ID must be unique within the group. Must be different from all other IDs (grouping and child item IDs).

Parameters

Groupposition to get the grouping location of the ID.

Return

The ID associated with the grouping.

public abstract Booleanhasstableids ()

Whether to specify a background data change for the ID of the grouped view and its child views also preserves that ID.

Return

Whether the same ID always points to the same object.

public abstract booleanischildselectable (int groupposition, intchildposition)

Specifies whether the child view of the location can be selected.

Parameters

Groupposition contains the grouped locations to get the child views.

Childposition the position of the sub-view.

Return

Whether the child view can be selected.

Attention:

In an XML layout file, you cannot use wrap_content values for the Android:layout_height property of Expandablelistview If the size of the first-level view on Expandablelistview is not strictly defined. (for example, if the upper-level view is ScrollView, you should not specify the value of Wrap_content because it can be any length.) However, if the upper-level view of the Expandablelistview has a specific size, such as 100 pixels, you can use wrap_content)

An explanation of the use of Android Expandablelistview

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.