• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > 【原创】Android ExpandableListView使用,expandablelistview

【原创】Android ExpandableListView使用,expandablelistview

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了expandablelistview,xexpandablelistview,android sqlite使用,android dialog使用,android okhttp使用等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

【原创】Android ExpandableListView使用,expandablelistview


ExpandableView的使用可以绑定到SimpleExpandableListAdapter,主要是看这个Adapter怎么用。 这个类默认的构造函数有9个参数, 很好地解释了什么叫做又臭又长。

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)

不过不用担心, 只要把Group开头的和Child开头的分成两组来看就好。 具体看下面注释部分。


代码:  
package com.example.zzp.testexpandablelist;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ExpandableListView list = (ExpandableListView) findViewById(R.id.expand_list);

        ArrayList<Map<String, String>> groupData = new ArrayList<>();
        int groupLayout = R.layout.group_view_group;
        String[] groupFrom = {"name", "type", "description"};
        int[] groupTo = {R.id.txt_view_name, R.id.txt_view_type, R.id.txt_view_description};

        ArrayList<ArrayList<Map<String, String>>> childData = new ArrayList<>();
        int childLayout = R.layout.group_view_child;
        String[] childFrom = {"ability"};
        int[] childTo = {R.id.txt_view_child_ability};

        for (int i = 0; i < 3; i++) {
            //初始化group数据
            HashMap<String, String> map = new HashMap<>();
            map.put("name", "device " + String.valueOf(i));
            map.put("type", "type " + String.valueOf(i));
            map.put("description", "Description of device " + String.valueOf(i));
            groupData.add(map);
            //初始化Child数据
            ArrayList<Map<String, String>> childDataList = new ArrayList<>();
            for (int j = 0; j < 4; j++) {
                HashMap<String, String> tmpMap = new HashMap<String, String>();
                tmpMap.put("ability", "ability " + String.valueOf(i) + String.valueOf(j));
                childDataList.add(tmpMap);
            }
            childData.add(childDataList);
        }

        /* 用四个group*数据来表示Group的表现方式,用四个child*的数据来表示Child的表示方式。
        groupData,其中的每一个Map代表了一个Group的所有要显示的数据,比如在GroupTab上你想显示name,type,description,那么就在Map里面用键值对放这几项就好了。
        groupLayout,只是一个视图,其中要包含有所有用于显示name,type,description等项目的元素。这些元素需要被放在groupTo里面。并且顺序要和groupFrom里面的key顺序对应。
        groupFrom,要显示的Group数据的key。
        groupTo,要显示的Group数据对应的View的ID。这些ID必须是之前定义的group布局里面的。

        Child基本上类似,也是每一个Map对应一个Child的所有数据项。第一层List,分到不同的Group,第二层List,分到不同的ChildItem,第三层就是Map了,每个Child的数据集合。
        * */
        SimpleExpandableListAdapter mArrayAdapter = new SimpleExpandableListAdapter(this, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo);
        list.setAdapter(mArrayAdapter);
    }
}

 



GroupView:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@android:color/holo_blue_light"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/txt_view_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:textSize="20dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txt_view_type"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/txt_view_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp" />
    </LinearLayout>
</LinearLayout>

 

 

ChildView:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txt_view_child_ability"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="18dp" />
</LinearLayout>

 

 

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP),expandablelistview
  • Android中使用ExpandableListView实现好友分组,expandablelistview
  • 可展开的列表组件——ExpandableListView深入解析,expandablelist展开
  • 安卓开发树形控件之ExpandableListView(一),expandablelistview
  • Android ExpandableListView相关介绍
  • 【原创】Android ExpandableListView使用,expandablelistview

相关文章

  • 2017-05-26Android小项目:计算器
  • 2017-05-26高并发低基数多字段任意组合查询的优化
  • 2017-05-26Linux文件和目录权限详细讲解,linux权限讲解
  • 2017-05-26手机影音9--视频播放器的高级功能(2),9--高级功能
  • 2017-05-26HTTP 首部字段详细介绍,首部字段详细介绍
  • 2017-05-26Google官方MVP模式示例项目解析 todo-mvp,mvptodo-mvp
  • 2017-05-26【1】Android 学习笔记 【第一个安卓程序】,android安卓
  • 2017-05-26Android刷机教程之LG Nexus 5X线刷官方Nexus系列教程,androidnexus
  • 2017-05-26Android学习笔记(26):Toast提示信息框浅析
  • 2017-05-26Android面试题(3),android面试题

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android 连接webservice(利用谷歌提供的jar包),androidwebservice
    • linux 破解版 confluence
    • okhttp3.4.1+retrofit2.1.0实现离线缓存,retrofitokhttp缓存
    • 安卓第十八天笔记--简单动画,安卓第十八天--
    • 我的Android第二课,Android
    • Android Studio Lambda Config,androidlambda
    • BadgeView使用,jsbadgeview使用方法
    • Android UI相关开源项目库汇总,android开源项目
    • android红米等关于读取本地文件夹图片获取路径的问题的解决,
    • 活动的生命周期系列(一)返回栈,生命周期系列

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有