ExpandableListView使用
来源:互联网 发布:vfp编程实例及提高 编辑:程序博客网 时间:2024/05/06 02:03
public class MainActivity extends Activity { private ExpandableListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv=(ExpandableListView) findViewById(R.id.exlistview); MyAdapter adapter=new MyAdapter(this); lv.setAdapter(adapter); lv.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, int arg3, long arg4) { // TODO Auto-generated method stub return false; } }); }}
自定义adapter
public class MyAdapter extends BaseExpandableListAdapter{ private Context context; private String [] st={"家人","朋友"}; private String [][] fimily={{"爸爸","妈妈","哥哥"},{"小王","小明","小红"}}; MyAdapter(Context context){ this.context=context; } @Override public Object getChild(int arg0, int arg1) { // TODO Auto-generated method stub return fimily[arg0][arg1]; } @Override public long getChildId(int arg0, int arg1) { // TODO Auto-generated method stub return arg1; } @Override public int getChildrenCount(int arg0) { // TODO Auto-generated method stub return fimily[arg0].length; } @Override public Object getGroup(int arg0) { // TODO Auto-generated method stub return st[arg0]; } @Override public int getGroupCount() { // TODO Auto-generated method stub return st.length; } @Override public long getGroupId(int arg0) { return arg0; } @Override public View getChildView(int arg0, int arg1, boolean arg2, View convertView, ViewGroup arg4) { viewHolder holder; if(convertView==null){ LayoutInflater inflater = LayoutInflater.from(context); convertView = inflater.inflate(R.layout.childview, null); holder=new viewHolder(); holder.tv=(TextView) convertView.findViewById(R.id.title); convertView.setTag(holder); }else{ holder=(viewHolder) convertView.getTag(); } holder.tv.setText(fimily[arg0][arg1]); return convertView; } @Override public View getGroupView(int arg0, boolean arg1, View convertView, ViewGroup v) { viewHolder holder; if(convertView==null){ LayoutInflater inflater = LayoutInflater.from(context); convertView = inflater.inflate(R.layout.grovview, null); holder=new viewHolder(); holder.tv=(TextView) convertView.findViewById(R.id.titles); convertView.setTag(holder); }else{ holder=(viewHolder) convertView.getTag(); } holder.tv.setText(st[arg0]); return convertView; } @Override public boolean isChildSelectable(int arg0, int arg1) { // 二级标签能否被选中 return true; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false; } class viewHolder{ TextView tv; }}
0 0
- ExpandableListView使用
- 使用ExpandableListView
- 使用ExpandableListView
- ExpandableListView使用
- ExpandableListView使用
- ExpandableListView使用
- ExpandableListView使用
- ExpandableListView使用
- ExpandableListView的使用
- ExpandableListView的使用
- android ExpandableListView使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- 转载:ExpandableListView的使用
- ExpandableListView的使用
- ExpandableListView 使用方式
- expandablelistview的使用
- Android ExpandableListView的使用
- 公交或地铁上刷卡机的unity实现思路
- 使用JS构建简单的虚拟小键盘
- Mac OS系统磁盘空间不断减少,直到为0
- 织梦模板安装常见问题解答
- 遍历窗口句柄
- ExpandableListView使用
- 比赛2016年暑假集训盲打首秀赛结果
- LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。
- 文章标题
- hadoop DataNode节点超时
- Android各大网络请求库的比较及实战
- hadoop HDFS入门
- cocos2dx-详细剖析lua(如何与lua集成,如何导出lua api,如何与lua交互)
- Java实现Mybatis将数据批量插入到Oracle数据库