zoukankan      html  css  js  c++  java
  • android ExpandableListActivity的使用

    package com.example.keKuoZhanLieBiao;
    
    import android.app.ExpandableListActivity;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.*;
    
    public class MyActivity extends ExpandableListActivity {
    
        String[] groups = {"常见问题", "功能帮助", "其他帮助"};
        String[][] children = {
                {"常见问题1", "常见问题2", "常见问题3"},
                {"功能问题1", "功能问题2", "功能问题3"},
                {"其他问题1", "其他问题2", "其他问题3"},
        };
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
    
                @Override
                public int getGroupCount() {
                    return groups.length;
                }
    
                @Override
                public int getChildrenCount(int i) {
                    return children[i].length;
                }
    
                @Override
                public Object getGroup(int i) {
                    return groups[i];
                }
    
                @Override
                public Object getChild(int i, int i2) {
                    return children[i][i2];
                }
    
                @Override
                public long getGroupId(int i) {
                    return i;
                }
    
                @Override
                public long getChildId(int i, int i2) {
                    return 0;
                }
    
                @Override
                public boolean hasStableIds() {
                    return false;
                }
    
    
                @Override
                public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
                    View view1 = LayoutInflater.from(MyActivity.this).inflate(R.layout.item_group, null);
                    TextView title = (TextView) view1.findViewById(R.id.gp_tv);
                    title.setText(groups[i]);
                    return view1;
                }
    
                @Override
                public View getChildView(int i, int i2, boolean b, View view, ViewGroup viewGroup) {
                    TextView textView = (TextView) LayoutInflater.from(MyActivity.this).inflate(R.layout.item_child, null);
                    textView.setText(children[i][i2]);
                    return textView;
                }
    
                @Override
                public boolean isChildSelectable(int i, int i2) {
                    return true;
                }
            };
    
    
            setListAdapter(adapter);
    
    //        绑定孩子点击事件
            this.getExpandableListView().setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
                    Toast.makeText(MyActivity.this, "你点击是"+children[i][i2], 1).show();
                    return true;
                }
            });
        }
    }
  • 相关阅读:
    如何快速查看archlinux pacman 软件记录?
    如何快速判断检查主机ip端口是否存活?
    如何在不清楚有哪些tag的情况下拉取docker镜像?
    如何使用docker版Openresty测试框架Test::Nginx进行测试?
    .net mvc4 使用 System.Web.Optimization 对javascript和style的引入、代码合并和压缩的优化(ScriptBundle,StyleBundle,Bund
    zen coding de 一些快捷功能
    C# Xpath
    一个SQL SERVER查询分析器非常好用的工具
    探索MSSQL执行计划
    博客园武林人士
  • 原文地址:https://www.cnblogs.com/wuyou/p/3516472.html
Copyright © 2011-2022 走看看