Android控件之ExpandableListView多级列表
来源:互联网 发布:文本特征提取算法 编辑:程序博客网 时间:2024/06/05 22:56
Android控件之ExpandableListView多级列表
效果展示:
直接上源码:
package com.example.expandablelistview;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.ExpandableListAdapter;import android.widget.ExpandableListView;import android.widget.ExpandableListView.OnChildClickListener;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity { private ExpandableListView expandableListView1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); expandableListView1=(ExpandableListView) findViewById(R.id.expandableListView1); expandableListView1.setAdapter(new myadapter()); expandableListView1.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(),childs[groupPosition][childPosition], 1000).show(); return true; } }); } private String[] groups= {"老师","朋友"}; private String[][] childs= {{"王老师","张老师","朱老师"},{"王小明","张小丽","朱晓红"}}; class myadapter extends BaseExpandableListAdapter{ @Override public int getGroupCount() { // TODO Auto-generated method stub return groups.length; } @Override public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return childs[groupPosition].length; } @Override public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return groups[groupPosition]; } @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childs[groupPosition][childPosition]; } @Override public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childPosition; } //这个方法一般不用重写 @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false;//这个方法一般不用重写 } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null) { convertView=getLayoutInflater().inflate(R.layout.group_layout,null); } TextView title= (TextView) convertView.findViewById(R.id.group_textView); title.setText(groups[groupPosition]); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null) { convertView=getLayoutInflater().inflate(R.layout.child_layout,null); } TextView title=(TextView) convertView.findViewById(R.id.child_textView); title.setText(childs[groupPosition][childPosition]); return convertView; } //这个方法是子选项是否可以被选中,我们直接返回true; @Override public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub return true; } }}
阅读全文
0 0
- Android控件之ExpandableListView多级列表
- Android ExpandableListView(多级列表)
- Android多级列表ExpandableListView使用实例
- 多级列表ExpandableListView
- Android ExpandableListView 展开列表控件
- ExpandableListView多级列表(二级列表)
- Android控件之ExpandableListView
- Android控件之ExpandableListView
- Android控件之ExpandableListView
- Android控件之ExpandableListView
- Android控件之ExpandableListView
- android控件之expandableListView
- Android UI编程(2)——多级列表(ExpandableListView)
- Android UI编程(2)——多级列表(ExpandableListView)
- 多级列表的学习:ExpandableListView
- ExpandableListView的使用多级列表
- 高级控件之分组列表视图(ExpandableListView)
- Android::ExpandableListView二级列表控件的使用
- DBCP2 连接池配置
- TLS/SSL 协议详解(11) Server Certificate
- 3.单件模式
- Android 6.0以上 解决recyclerview 在 scrollview 中不能全部显示,高度不正常的问题
- 实验楼Git实战教程-初始化 Git 仓库
- Android控件之ExpandableListView多级列表
- MySQL删除数据库
- Docker技术剖析--dockerfile构建容器
- 使用CSS设置超链接
- linux命令的初步认识
- PHP 使用PDO持久化连接
- 24:正常血压
- css 协议弹出层卡的问题
- 教程:Connectionist Temporal Classification详解补充