Android详细教程(基础篇):二十四、View组件高级篇:ExpandableListView树形组件详解

本文深入探讨Android中的ExpandableListView组件,讲解如何结合BaseExpandableListAdapter实现树形数据展示。通过示例代码,展示了配置及在Activity中使用Adapter的方法。
摘要由CSDN通过智能技术生成

7.20. ExpandableListView(树形组件)

 

需结合适配器BaseExpandableListAdapter完成。

示例:

配置:activity_expandable_list_view.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

            xmlns:android="http://schemas.android.com/apk/res/android"

            android:orientation="vertical"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent">

            <ExpandableListView

                       android:id="@+id/elistview"

                       android:layout_width="fill_parent"

                       android:layout_height="wrap_content" />

</LinearLayout>

 

Activity:

package com.makyan.demo;

import android.app.Activity;

import android.os.Bundle;

import android.view.ContextMenu;

import android.view.ContextMenu.ContextMenuInfo;

import android.view.View;

import android.widget.ExpandableListAdapter;

import android.widget.ExpandableListView;

import android.widget.ExpandableListView.OnChildClickListener;

import android.widget.ExpandableListView.OnGroupClickListener;

import android.widget.ExpandableListView.OnGroupCollapseListener;

import android.widget.ExpandableListView.OnGroupExpandListener;

import android.widget.Toast;

public class ExpandableListViewActivity extends Activity {

            private ExpandableListView elistview = null;                              // 定义树型组件

            private ExpandableListAdapter adapter = null;                          // 定义适配器对象

            @Override

            public void onCreate(Bundle savedInstanceState) {

                       super.onCreate(savedInstanceState);

                       super.setContentView(R.layout.activity_expandable_list_view);                                           // 默认布局管理器

                       elistview = (ExpandableListView) super.findViewById(R.id.elistview);                                              // 取得组件

                       adapter = new MyExpandableListAdapter(this); // 实例化适配器

                       elistview.setAdapter(adapter);                             // 设置适配器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值