android BaseExpandableListAdapter 二级菜单适配器
来源:互联网 发布:cf冰域炸服器软件 编辑:程序博客网 时间:2024/04/29 09:33
android BaseExpandableListAdapter 二级菜单适配器
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ExpandableListView android:id="@+id/home_a_list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/ll_title" android:childDivider="#EEEEEE" android:divider="#c8c7cc" android:dividerHeight="1dp" android:gravity="center" android:groupIndicator="@null" android:listSelector="#00000000" /></RelativeLayout>MainActivity.java
package com.zcycjy.mobile.fragment;import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.ExpandableListView;import android.widget.ExpandableListView.OnChildClickListener;import android.widget.ExpandableListView.OnGroupExpandListener;import com.zcycjy.mobile.R;import com.zcycjy.mobile.adapter.ExpandableAdapter;import com.zcycjy.mobile.entity.HomeType;/** * @author itps * */public class MainActivity extends Activity {// 标题private List<String> groupArray = new ArrayList<String>();// 子标题private List<List<HomeType>> childArray = new ArrayList<List<HomeType>>();private ExpandableAdapter adapters;private ExpandableListView expandableListView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);getDatas(0);initView();}private void initView() {expandableListView = (ExpandableListView)findViewById(R.id.home_a_list);adapters = new ExpandableAdapter(this, groupArray, childArray);expandableListView.setAdapter(adapters);expandableListView.setOnChildClickListener(new OnChildClickListener() {@Overridepublic boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {// TODO Auto-generated method stubHomeType ht = (HomeType) adapters.getChild(groupPosition,childPosition);return false;}});expandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {@Overridepublic void onGroupExpand(int groupPosition) {for (int i = 0; i < groupArray.size(); i++) {if (groupPosition != i) {expandableListView.collapseGroup(i);}}}});}private void getDatas(int type) {// 会计groupArray.add("注册会计师");List<HomeType> ta1 = new ArrayList<HomeType>();ta1.add(new HomeType("会计", "000001"));ta1.add(new HomeType("审计", "000002"));ta1.add(new HomeType("财务成本管理", "000003"));ta1.add(new HomeType("税法", "000004"));ta1.add(new HomeType("经济法", "000005"));ta1.add(new HomeType("公司战略与风险管理", "000006"));groupArray.add("高级会计职称");List<HomeType> ta2 = new ArrayList<HomeType>();ta2.add(new HomeType("高级会计实务", "000011"));groupArray.add("中级会计职称");List<HomeType> ta3 = new ArrayList<HomeType>();ta3.add(new HomeType("中级会计实务", "000021"));ta3.add(new HomeType("中级经济法", "000022"));ta3.add(new HomeType("中级财务管理", "000023"));childArray.add(ta1);childArray.add(ta2);childArray.add(ta3);}}ExpandableAdapter.java
package com.zcycjy.mobile.adapter;import java.util.List;import com.zcycjy.mobile.entity.HomeType;import android.app.Activity;import android.graphics.Color;import android.view.Gravity;import android.view.View;import android.view.ViewGroup;import android.widget.AbsListView;import android.widget.BaseExpandableListAdapter;import android.widget.TextView;public class ExpandableAdapter extends BaseExpandableListAdapter {private List<String> groupArray;private List<List<HomeType>> childArray;private Activity activity;public ExpandableAdapter(Activity act, List<String> groupArray,List<List<HomeType>> childArray) {this.activity = act;this.groupArray = groupArray;this.childArray = childArray;}@Overridepublic Object getChild(int groupPosition, int childPosition) {// TODO Auto-generated method stubreturn childArray.get(groupPosition).get(childPosition);}@Overridepublic long getChildId(int groupPosition, int childPosition) {// TODO Auto-generated method stubreturn childPosition;}@Overridepublic View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) {// TODO Auto-generated method stubString string = childArray.get(groupPosition).get(childPosition).getTypeName();return getGenericView(string, 1);}@Overridepublic int getChildrenCount(int groupPosition) {// TODO Auto-generated method stubreturn childArray == null ? 0 : childArray.get(groupPosition).size();}@Overridepublic Object getGroup(int groupPosition) {// TODO Auto-generated method stubreturn groupArray.get(groupPosition);}@Overridepublic int getGroupCount() {// TODO Auto-generated method stubreturn groupArray == null ? 0 : groupArray.size();}@Overridepublic long getGroupId(int groupPosition) {// TODO Auto-generated method stubreturn groupPosition;}@Overridepublic View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {// TODO Auto-generated method stubString string = groupArray.get(groupPosition);return getGenericView(string, 0);}@Overridepublic boolean hasStableIds() {// TODO Auto-generated method stubreturn false;}@Overridepublic boolean isChildSelectable(int groupPosition, int childPosition) {// TODO Auto-generated method stubreturn true;}/** * Children 's View * * @param string * @return */public TextView getGenericView(String string, int i) {AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);TextView text = new TextView(activity);text.setLayoutParams(layoutParams);// Center the text verticallytext.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);// Set the text starting positionif (i == 1) {text.setTextColor(Color.parseColor("#000000"));text.setPadding(70, 10, 0, 10);text.setText(string + " >>>");} else {text.setTextColor(Color.parseColor("#F39801"));text.setPadding(40, 20, 0, 20);text.setText(string + " ▼▼▼");}return text;}}
0 0
- android BaseExpandableListAdapter 二级菜单适配器
- ExpandableListAdapter二级菜单适配器
- Android ExpandableListView 进行二级扩展 (BaseExpandableListAdapter)
- android二级列表(BaseExpandableListAdapter的使用) 仿通话记录
- 【Android】树形菜单、扩展下拉菜单BaseExpandableListAdapter、AbsListView
- 【Android】树形菜单、扩展下拉菜单BaseExpandableListAdapter、AbsListView
- android 适配器Adpter的使用总结 之 BaseExpandableListAdapter
- Android BaseExpandableListAdapter
- Android BaseExpandableListAdapter
- Android BaseExpandableListAdapter
- Android 二级菜单
- Android 二级菜单最终版
- android 二级菜单实现
- Android 二级动画弹出菜单
- Android中实现二级菜单
- android 二级菜单的实现
- Android自定义二级联动菜单
- Android Laucher3 去掉二级菜单
- iOS中的KVO使用
- 将matlab中数据导出VC导入
- spring 定时器配置
- swift 绘图
- Linux网络编程--服务端判断客户端断开的经验方法
- android BaseExpandableListAdapter 二级菜单适配器
- android之自定义自己的log的格式
- JavaSE入门学习27:Java常用类之String类(上)
- C++ 如何定义动态二维数组?
- salt快速部署
- Storm详解二、写第一个Storm应用
- 2048小游戏——网页版(基础篇)
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- 主成分分析(Principal components analysis)-最小平方误差解释