ExpandableListView的首次加载全部展开,并且点击Group不收缩,去掉Group左边的箭头

    xiaoxiao2026-03-13  8

    1、首次加载全部展开:

    mExpandableListView.setAdapter(mExpandableListViewAdapter); for (int i = 0; i < mDataGroup.size(); i++) { mExpandableListView.expandGroup(i); } 提醒:加载前别忘了判断adapter是否为空和有没有Group数据哦 2、不能点击收缩: mExpandableListView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { return true; } });

    把ExpandableListView的组点击事件屏蔽

    3、ExpandableListView的长按事件

    网上的资料不少,但是没几个管用的,最后找到一个确实可用的,在这分享下:

    (1) 

    //长按事件 mExpandableListView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.setHeaderTitle("选择操作"); menu.add(0, DOWNLOAD_RETRY, 0, "重试"); menu.add(0, DOWNLOAD_DEL, 0, "删除"); menu.add(0, DOWNLOAD_START, 0, "启动"); } });

    (2) /** * 长按菜单响应函数 */ @Override public boolean onContextItemSelected(MenuItem item) { //关键代码 ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo(); int type = ExpandableListView.getPackedPositionType(info.packedPosition); if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { //上面的type设定这里类型的判定!这里是child判定! int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); //在child判定里面,获取该child所属group! int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); //在child判定里面,获取该child所属position! switch (item.getItemId()) { case DOWNLOAD_RETRY: makeTextShort("我是重试"); break; case DOWNLOAD_DEL: makeTextShort("我是删除"); break; case DOWNLOAD_START: makeTextShort("我是启动"); default: break; } return true; } return false; }

    4、去掉 ExpandableListView Group 上的箭头

    可以 xml 布局中

    android:groupIndicator="@null"也可以 java 代码中

    mExpandableListView.setGroupIndicator(null);

    5、目前上面浮动的TextView没有实现,iOS的貌似是叫 IphoneTreeView 

    转载请注明原文地址: https://ju.6miu.com/read-1307917.html
    最新回复(0)