日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 多级分组,android 二级菜单(类似QQ分组)

發布時間:2025/3/12 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 多级分组,android 二级菜单(类似QQ分组) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注意點:1)適配器BaseExpandableListAdapter

2)數據源(數組、集合都行)(重點)

/**

*?Created?by?mb?on?2014/11/18.

*?二級菜單適配器

*/

public?class?MyExpandableListAdapter?extends?BaseExpandableListAdapter?{

private?Context?context;

List?groups;//String?[]?groups?=?{};

List>?childs;?//String?[]?[]?childs?=?{{},{},};

ViewHolder?holder;

public?MyExpandableListAdapter(Context?context,?List?groups,?List>?childs)?{

this.context?=?context;

this.groups?=?groups;

this.childs?=?childs;

}

@Override

public?int?getGroupCount()?{

return?groups.size();

}

@Override

public?int?getChildrenCount(int?groupPosition)?{

return?childs.get(groupPosition).size();

}

@Override

public?Object?getGroup(int?groupPosition)?{

return?groups.get(groupPosition);

}

@Override

public?Object?getChild(int?groupPosition,?int?childPosition)?{

return?childs.get(groupPosition).get(childPosition);

}

@Override

public?long?getGroupId(int?groupPosition)?{

return?groupPosition;

}

@Override

public?long?getChildId(int?groupPosition,?int?childPosition)?{

return?childPosition;

}

@Override

public?boolean?hasStableIds()?{

return?true;

}

@Override

public?View?getGroupView(int?groupPosition,?boolean?isExpanded,?View?convertView1,?ViewGroup?parent)?{

//自定義組視圖

return?convertView1;

}

@Override

public?View?getChildView(int?groupPosition,?int?childPosition,?boolean?isLastChild,?View?convertView,?ViewGroup?parent)?{

//自定義孩子視圖

return?convertView;

}

@Override

public?boolean?isChildSelectable(int?groupPosition,?int?childPosition)?{

return?true;

}

public?static?class?ViewHolder?{

//控件

}

}

事件監聽:

myExpandableListAdapter?=?new?MyExpandableListAdapter(context,?groups,?childs);

expandableListView.setAdapter(myExpandableListAdapter);

expandableListView.setOnGroupClickListener(new?ExpandableListView.OnGroupClickListener()?{

@Override

public?boolean?onGroupClick(ExpandableListView?parent,?View?v,?int?groupPosition,?long?id)?{

int?count?=?myExpandableListAdapter.getChildrenCount(groupPosition);

if?(count?<=?0)?{

activity.showCustomToast("...");

}

return?false;?//?---此處返回true??點擊后不能展開組??具體原因知道的留言

}

});

expandableListView.setOnChildClickListener(new?ExpandableListView.OnChildClickListener()?{

@Override

public?boolean?onChildClick(ExpandableListView?parent,?View?v,?int?groupPosition,?int?childPosition,?long?id)?{

return?false;

}

});

默認展開所有菜單:

for (int i = 0; i < myExpandableListAdapter.getGroupCount(); i++) {

expandableListView.expandGroup(i);

}

總結

以上是生活随笔為你收集整理的android 多级分组,android 二级菜单(类似QQ分组)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。