ExpandableListView(可扩展的listView)

本文详细介绍了Android中ExpandableListView的使用,包括布局代码和运行效果展示,帮助开发者理解如何在应用中实现可扩展的列表视图功能。
摘要由CSDN通过智能技术生成

代码:

class MainActivity extends AppCompatActivity {

    private String[] groups={"好友","同学"};
    private String[][] childs={
  {"Tom","Jerry","Jeck"},{"XY","WX","YH"}};
    ExpandableListView el;
    MyExpandableAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        el= (ExpandableListView) findViewById(R.id.expand_listview);
        adapter=new MyExpandableAdapter(getBaseContext(),groups,childs);
        el.setAdapter(adapter);
        el.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                Toast.makeText(MainActivity.this, "当前位置"+childs[groupPosition][childPosition], Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }
}
**********************************************************************
public class MyExpandableAdapter extends BaseExpandableListAdapter {

    private String[] groups;
    private String[][] childs;
    Context m
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值