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;
            }
        });
    }
}

 

转载于:https://www.cnblogs.com/wuyou/p/3516472.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值