ExpandableListView(下拉列表)实现
来源:互联网 发布:网络数据流量检测工具 编辑:程序博客网 时间:2024/05/29 23:44
package liu;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.ExpandableListView;import android.widget.ExpandableListView.OnChildClickListener;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;import com.example.demo_0330.R;public class ExpandableListView_Activity extends Activity {private ExpandableListView listview;private String[] groups = { "家人", "朋友", "亲戚" };private String[][] groupser = { { "关羽", "刘备", "张飞" },{ "孙悟空", "沙和尚", "猪八戒" }, { "旭哥", "琳哥", "徐哥" } };protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.expandablelistview_activity);listview = (ExpandableListView) findViewById(R.id.yi);listview.setAdapter(new adapter());//点击事件listview.setOnChildClickListener(new OnChildClickListener() {public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {Toast.makeText(ExpandableListView_Activity.this, groupser[groupPosition][childPosition], 0).show();return false;}});}// 适配器class adapter extends BaseExpandableListAdapter {// 总的组数public int getGroupCount() {return groups.length;}// 子类的总数public int getChildrenCount(int groupPosition) {return groupser[groupPosition].length;}// 获取二级分类对象public Object getGroup(int groupPosition) {return groups[groupPosition];}// 获取二级分类里的对象public Object getChild(int groupPosition, int childPosition) {return groupser[groupPosition][groupPosition];}// 返回相应的idpublic long getGroupId(int groupPosition) {return groupPosition;}// 返回相应的idpublic long getChildId(int groupPosition, int childPosition) {return childPosition;}// 返回状态 可以用不重写public boolean hasStableIds() {// TODO Auto-generated method stubreturn false;}// 分组布局public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {if (convertView == null) {convertView = getLayoutInflater().inflate(R.layout.group_layout, null);}ImageView iv = (ImageView) convertView.findViewById(R.id.tupian);TextView tv = (TextView) convertView.findViewById(R.id.title);tv.setText(groups[groupPosition]);return convertView;}// 分组内部布局,每一组的布局public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) {if (convertView == null) {convertView = getLayoutInflater().inflate(R.layout.group_erji_layout, null);}ImageView iv = (ImageView) convertView.findViewById(R.id.tupian);TextView tv = (TextView) convertView.findViewById(R.id.title);tv.setText(groupser[groupPosition][childPosition]);return convertView;}// 二级是否可以被选中public boolean isChildSelectable(int groupPosition, int childPosition) {return true;}}}
0 0
- ExpandableListView(下拉列表)实现
- ExpandableListView 实现QQ的下拉列表
- ExpandableListView------下拉列表
- ExpandableListView扩展下拉列表
- 【Android基础篇】使用ExpandableListView实现自定义的下拉列表
- 【Android基础篇】使用ExpandableListView实现自定义的下拉列表
- 扩展下拉列表ExpandableListView(一)
- 扩展下拉列表ExpandableListView(二)
- ExpandableListView 功能界面布局探究之三(没有child的下拉列表,group不展开的实现)
- 可扩展的下拉列表—ExpandableListView
- ExpandableListView实现的简单类似QQ好友界面的可展开下拉列表
- ExpandableListView+Dialog实现弹出二级下拉列表选项。可自由用于Activity和Fragment中
- ExpandableListView实现商品列表折叠
- ExpandableListView三级列表的实现
- 下拉列表实现(自定义)
- android 实现QQ好友列表(扩展listview:ExpandableListView)
- android 实现QQ好友列表(扩展listview:ExpandableListView)
- 65 Android ExpandableListView (QQ好友列表的实现)
- CSS hack
- plsql无法连接64位oracle数据库的解决方法(图文解说)
- Android学习之RecyclerView
- android事件机制
- PIC18F14k50 中断
- ExpandableListView(下拉列表)实现
- 在反向代理中添加例外
- Android:Layout_weight的深刻理解
- servlet下载文件到本地
- SpringMVC中hibernate中一对多关系,懒加载转JSON问题
- 【UVA 10561】 Treblecross|博弈论|SG函数
- 数据中心网络三大热门技术
- Dialog中EditText不弹出键盘解决方案
- Java 多线程线程池 - 线程池原理