• 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;
                }
            });
        }
    }
  • 相关阅读:
    Silverlight 程序启动
    在RHEL 下安装PostgreSQL
    在x64 Linux上安装PostGIS
    Datalist或Repeater里点击某列内容将放到文本框中以便编辑,文本框失去焦点后信息即可修改成功
    javascript“设为首页”与“加入收藏”兼容多浏览器代码
    百度地图api 3D图层添加 代码
    百度地图api 开发日志 范围加载
    CLR via C# 第一章 (1)
    首個字母排序
    内存管理
  • 原文地址:https://www.cnblogs.com/wuyou/p/3516472.html
Copyright © 2020-2023  润新知