Android 二级列表
来源:互联网 发布:python 文件函数 编辑:程序博客网 时间:2024/06/15 18:42
请求网络数据二级列表的GitHub地址:点击打开链接 https://github.com/zhouxua/Erji_liebiao
//适配器
public class MyExpandableListView extends BaseExpandableListAdapter { private Context context; private LayoutInflater inflater; public MyExpandableListView(Context context){ this.context = context; inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } private String[] groups = {"A", "B", "C"}; //注意,字符数组不要写成{{"A1,A2,A3,A4"}, {"B1,B2,B3,B4,B5"}, {"C1,C2,C3,C4"}}*/ private String[][] childs={{"A1","A2","A3","A4"},{"A1","A2","A3", "B4"},{"A1","A2","A3","C4"}}; //返回一级列表的个数 @Override public int getGroupCount() { return groups.length; } //返回每个二级列表的个数 @Override public int getChildrenCount(int groupPosition) { //参数groupPosition表示第几个一级列表 Log.d("smyhvae", "-->" + groupPosition); return childs[groupPosition].length; } //返回一级列表的单个item(返回的是对象) @Override public Object getGroup(int groupPosition) { return groups[groupPosition]; } //返回二级列表中的单个item(返回的是对象) @Override public Object getChild(int groupPosition, int childPosition) { return childs[groupPosition][childPosition]; //不要误写成groups[groupPosition][childPosition] } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } //每个item的id是否是固定?一般为true @Override public boolean hasStableIds() { return true; } //【重要】填充一级列表 @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.item_group, null); } TextView tv_group = (TextView) convertView.findViewById(R.id.tv_group); tv_group.setText(groups[groupPosition]); return convertView; } //【重要】填充二级列表 @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.item_child, null); } ImageView iv_child = (ImageView) convertView.findViewById(R.id.iv_child); TextView tv_child = (TextView) convertView.findViewById(R.id.tv_child); //iv_child.setImageResource(resId); tv_child.setText(childs[groupPosition][childPosition]); return convertView; } //二级列表中的item是否能够被选中?可以改为true @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; }}
//mainactivity中
public class MainActivity extends AppCompatActivity { //View private ExpandableListView expandableListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); expandableListView = (ExpandableListView) findViewById(R.id.expandableListView); expandableListView.setAdapter(new MyExpandableListView(MainActivity.this)); }}
阅读全文
0 0
- android二级listview列表
- android二级listview列表
- android二级listview列表
- android二级listview列表
- Android ExpandableListView (二级列表)
- android二级listview列表
- android二级listview列表
- android ExpandableListView二级列表
- android二级listview列表
- Android 二级列表
- Android二级列表
- Android 二级列表
- Android 横向二级ListView列表
- Android二级分类列表ListView
- Android二级分类列表GirdView
- Android二级列表菜单框架
- Android RecyclerView 二级列表实现
- Android 二级列表购物车
- 简洁的网络拦截器
- 【Scikit-Learn 中文文档】6 支持向量机
- 断点续传
- jquery chosen 插件使用
- centos 7.3 U盘安装血泪史
- Android 二级列表
- 算法谜题之解决
- 数据库安装及应用
- C++字符流操作
- GreenDao
- 实现MySQL高可用架构之MHA
- 【Scikit-Learn 中文文档】7 随机梯度下降
- C++引用小结
- 谈谈Flyerinternational招IB带领学员致富 内幕秘籍采访