android button图片expandablelistview 多组radiobutton

先直接上图,1:、展开的效果图:2:后面的是点击收缩的效果图。3:下面就是代码部分:我们要定义2个集合用来存储数据,一个是groupItem的数据,一个是childItem的数据private List&Map&String, Object&& groupList = new ArrayList&Map&String, Object&&();// 分组名称public List&List&Map&String, Object&&& childList = new ArrayList&List&Map&String, Object&&&();// 详细名称定义一个控件:public ExpandableListVie // 2层列表将我们获取到的数据填充到里面去:& & & & & & & &adapter = new JingCaiZuQiuWinBeatLotteryAdapter(MainActivity.this, winBeatLotteryMain, groupList, childList);expandablelistview.setAdapter(adapter);expandablelistview.setGroupIndicator(null);// 去掉group控件默认的箭头// 分组展开expandablelistview.setOnGroupExpandListener(new OnGroupExpandListener() {public void onGroupExpand(int groupPosition) {// expandablelistview.expandGroup(groupPosition);}});// 分组关闭expandablelistview.setOnGroupCollapseListener(new OnGroupCollapseListener() {public void onGroupCollapse(int groupPosition) {// expandablelistview.collapseGroup(groupPosition);}});// 子项单击/** expandablelistview.setOnChildClickListener(new OnChildClickListener()* { public boolean onChildClick(ExpandableListView arg0, View arg1, int* groupPosition, int childPosition, long arg4) { } });*///全部展开,默认int groupCount = expandablelistview.getCount();for (int i = 0; i & groupC i++) {expandablelistview.expandGroup(i);}其实很简单,在这里我附上我的一个小demo源代码。里面有注释。在我的资源里面有下载。稍后我会给出链接。
无相关信息页面导航:
→ 正文内容 Android中ExpandableListView的用法
Android中ExpandableListView的用法实例
这篇文章主要介绍了Android中ExpandableListView的用法,以实例形式展示了Android中的下拉list控件的用法,需要的朋友可以参考下
本文实例讲述了Android中ExpandableListView的用法,ExpandableListView是android中可以实现下拉list的一个控件,具体的实现方法如下:
首先:在layout的xml文件中定义一个ExpandableListView
代码如下:&LinearLayout&&
&&& android:id="@+id/linearLayout"&
&&& android:layout_width="fill_parent"&&
&&& android:layout_height="fill_parent"&
&&& androidrientation="vertical"&
&&& &ExpandableListView&
&&& android:id="@+id/expandableListView"&
&&& android:layout_width="fill_parent"&
&&& android:layout_height="wrap_content"&
&&&&&&& /&&
&/LinearLayout&
定义两个List,用来存放控件中Group/Child中的String
代码如下:private List&String& groupA&
private List&List&String&& childA
对这两个List进行初始化,并插入一些数据
代码如下:groupArray = new ArrayList&String&();&
childArray = new ArrayList&List&String&&();&
groupArray.add("第一行");&
groupArray.add("第二行");&
List&String& tempArray = new ArrayList&String&();&
tempArray.add("第一条");&
tempArray.add("第二条");&
tempArray.add("第三条");&
for(int index = 0; index &groupArray.size(); ++index)&
&&& childArray.add(tempArray);&
定义ExpandableListView的Adapter
代码如下://ExpandableListView的Adapter&
public class ExpandableAdapter extends BaseExpandableListAdapter&
&&& public ExpandableAdapter(Activity a)&
&&&&&&& activity =&
&&& public Object getChild(int groupPosition, int childPosition)&
&&&&&&& return childArray.get(groupPosition).get(childPosition);&
&&& public long getChildId(int groupPosition, int childPosition)&
&&&&&&& return childP&
&&& public int getChildrenCount(int groupPosition)&
&&&&&&& return childArray.get(groupPosition).size();&
&&& public View getChildView(int groupPosition, int childPosition,&
&&&&&&&&&&& boolean isLastChild, View convertView, ViewGroup parent)&
&&&&&&& String string = childArray.get(groupPosition).get(childPosition);&
&&&&&&& return getGenericView(string);&
&&& // group method stub&
&&& public Object getGroup(int groupPosition)&
&&&&&&& return groupArray.get(groupPosition);&
&&& public int getGroupCount()&
&&&&&&& return groupArray.size();&
&&& public long getGroupId(int groupPosition)&
&&&&&&& return groupP&
&&& public View getGroupView(int groupPosition, boolean isExpanded,&
&&&&&&&&&&& View convertView, ViewGroup parent)&
&&&&&&& String string = groupArray.get(groupPosition);&
&&&&&&& return getGenericView(string);&
&&& // View stub to create Group/Children 's View&
&&& public TextView getGenericView(String string)&
&&&&&&& // Layout parameters for the ExpandableListView&
&&&&&&& AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(&
&&&&&&&&&&&&&&& ViewGroup.LayoutParams.FILL_PARENT, 64);&
&&&&&&& TextView text = new TextView(activity);&
&&&&&&& text.setLayoutParams(layoutParams);&
&&&&&&& // Center the text vertically&
&&&&&&& text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);&
&&&&&&& // Set the text starting position&
&&&&&&& text.setPadding(36, 0, 0, 0);&
&&&&&&& text.setText(string);&
&&& public boolean hasStableIds()&
&&& public boolean isChildSelectable(int groupPosition, int childPosition)&
最后,给定义好的ExpandableListView添加上Adapter
代码如下:ExpandableListView expandableListView = (ExpandableListView)findViewById(R.id.expandableListView);&
expandableListView.setAdapter(new ExpandableAdapter(Main.this));
希望本文所述对大家的Android程序设计有所帮助。
您可能感兴趣的文章:
上一篇:下一篇:
最 近 更 新
热 点 排 行
1234567891035609人阅读
Android中ExpandableListView的使用
ExpandableListView是android中可以实现下拉list的一个控件,具体的实现方法如下:
首先:在layout的xml文件中定义一个ExpandableListView
&&&&android:id
=&@+id/linearLayout&
&&&&android:layout_width
=&fill_parent&
&&&&android:layout_height
=&fill_parent&
&&&&androidrientation
=&vertical&
&&&&android:id
=&@+id/expandableListView&
&&&&android:layout_width
=&fill_parent&
&&&&android:layout_height
=&wrap_content&
定义两个List,用来存放控件中Group/Child中的String
&List&String&&groupA&&
&List&List&String&&&childA&&
对这两个List进行初始化,并插入一些数据
groupArray&=&new
&ArrayList&String&();&&
childArray&=&new
&ArrayList&List&String&&();&&
groupArray.add(&第一行&
groupArray.add(&第二行&
List&String&&tempArray&=&new
&ArrayList&String&();&&
tempArray.add(&第一条&
tempArray.add(&第二条&
tempArray.add(&第三条&
&index&=&0
;&index&&groupArray.size();&++index)&&
&&&&childArray.add(tempArray);&&
定义ExpandableListView的Adapter
&ExpandableAdapter&extends
&BaseExpandableListAdapter&&
&&&&Activity&&&
&&&&public
&ExpandableAdapter(Activity&a)&&
&&&&&&&&activity&=&a;&&
&&&&public
&Object&getChild(int
&groupPosition,&int
&childPosition)&&
&&&&&&&&return
&childArray.get(groupPosition).get(childPosition);&&
&&&&public
&getChildId(int
&groupPosition,&int
&childPosition)&&
&&&&&&&&return
&&&&public
&getChildrenCount(int
&groupPosition)&&
&&&&&&&&return
&childArray.get(groupPosition).size();&&
&&&&public
&View&getChildView(int
&groupPosition,&int
&childPosition,&&
&&&&&&&&&&&&boolean
&isLastChild,&View&convertView,&ViewGroup&parent)&&
&&&&&&&&String&string&=&childArray.get(groupPosition).get(childPosition);&&
&&&&&&&&return
&getGenericView(string);&&
&&&&public
&Object&getGroup(int
&groupPosition)&&
&&&&&&&&return
&groupArray.get(groupPosition);&&
&&&&public
&getGroupCount()&&
&&&&&&&&return
&groupArray.size();&&
&&&&public
&getGroupId(int
&groupPosition)&&
&&&&&&&&return
&&&&public
&View&getGroupView(int
&groupPosition,&boolean
&isExpanded,&&
&&&&&&&&&&&&View&convertView,&ViewGroup&parent)&&
&&&&&&&&String&string&=&groupArray.get(groupPosition);&&
&&&&&&&&return
&getGenericView(string);&&
&&&&public
&TextView&getGenericView(String&string)&&
&&&&&&&&AbsListView.LayoutParams&layoutParams&=&new
&AbsListView.LayoutParams(&&
&&&&&&&&&&&&&&&&ViewGroup.LayoutParams.FILL_PARENT,&64
&&&&&&&&TextView&text&=&new
&TextView(activity);&&
&&&&&&&&text.setLayoutParams(layoutParams);&&
&&&&&&&&text.setGravity(Gravity.CENTER_VERTICAL&|&Gravity.LEFT);&&
&&&&&&&&text.setPadding(36
&&&&&&&&text.setText(string);&&
&&&&&&&&return
&&&&public
&hasStableIds()&&
&&&&&&&&return
&&&&public
&isChildSelectable(int
&groupPosition,&int
&childPosition)&&
&&&&&&&&return
最后,给定义好的ExpandableListView添加上Adapter
ExpandableListView&expandableListView&=&(ExpandableListView)findViewById(R.id.expandableListView);&&
expandableListView.setAdapter(new
&ExpandableAdapter(Main.this
运行即可见效果~~~
----------------------------------------------------------------------------------------------------------------
先看效果,过瘾一番。
&源码下载:
  ExpandableListView是Android中的手风琴,本人感觉效果相当棒。
  一、ExpandableListView介绍
    一个垂直滚动的显示两个级别(Child,Group)列表项的视图,列表项来自ExpandableListAdapter 。组可以单独展开。
  1.重要方法
      expandGroup
(int groupPos) :在分组列表视图中
展开一组,
      setSelectedGroup
(int groupPosition) :设置选择指定的组。
      setSelectedChild
(int groupPosition, int childPosition, boolean shouldExpandGroup) :设置选择指定的子项。
      getPackedPositionGroup
(long packedPosition) :返回所选择的组
      getPackedPositionForChild
(int groupPosition, int childPosition) :返回所选择的子项
      getPackedPositionType
(long packedPosition) :返回所选择项的类型(Child,Group)
      isGroupExpanded
(int groupPosition) :判断此组是否展开
  2.代码:
ExpandableListContextMenuInfo menuInfo=(ExpandableListContextMenuInfo)item.getMenuInfo();
&&String title=((TextView)menuInfo.targetView).getText().toString();
&&int type=ExpandableListView.getPackedPositionType(menuInfo.packedPosition);
&&if (type==ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
&&int&groupPos =ExpandableListView.getPackedPositionGroup(menuInfo.packedPosition);
&&int&childPos =ExpandableListView.getPackedPositionChild(menuInfo.packedPosition);
二、ExpandableListAdapter
    一个接口,将基础数据链接到一个ExpandableListView。
此接口的实施将提供访问Child的数据(由组分类),并实例化的Child和Group。
  1.重要方法
    getChildId
(int groupPosition, int childPosition) 获取与在给定组给予孩子相关的数据。
    getChildrenCount
(int groupPosition) 返回在指定Group的Child数目。
  2.代码
&public class MyExpandableListAdapter extends BaseExpandableListAdapter {
&&&&&&&& // Sample data set.& children[i] contains the children (String[]) for groups[i].
&&&&&&&& public String[] groups = { &我的好友&, &新疆同学&, &亲戚&, &同事& };
&&&&&&&& public String[][] children = {
&&&&&&&&&&&&&&&& { &胡算林&, &张俊峰&, &王志军&, &二人& },
&&&&&&&&&&&&&&&& { &李秀婷&, &蔡乔&, &别高&, &余音& },
&&&&&&&&&&&&&&&& { &摊派新&, &张爱明& },
&&&&&&&&&&&&&&&& { &马超&, &司道光& }
&&&&&&&& };
&&&&&&&& public Object getChild(int groupPosition, int childPosition) {
&&&&&&&&&&&& return children[groupPosition][childPosition];
&&&&&&&& }
&&&&&&&& public long getChildId(int groupPosition, int childPosition) {
&&&&&&&&&&&& return childP
&&&&&&&& }
&&&&&&&& public int getChildrenCount(int groupPosition) {
&&&&&&&&&&&& return children[groupPosition].
&&&&&&&& }
&&&&&&&& public TextView getGenericView() {
&&&&&&&&&&&& // Layout parameters for the ExpandableListView
&&&&&&&&&&&& AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
&&&&&&&&&&&&&&&&&&&& ViewGroup.LayoutParams.MATCH_PARENT, 64);
&&&&&&&&&&&& TextView textView = new TextView(ExpandableListDemo.this);
&&&&&&&&&&&& textView.setLayoutParams(lp);
&&&&&&&&&&&& // Center the text vertically
&&&&&&&&&&&& textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
&&&&&&&&&&&& // Set the text starting position
&&&&&&&&&&&& textView.setPadding(36, 0, 0, 0);
&&&&&&&&&&&& return textV
&&&&&&&& }
&&&&&&&& public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
&&&&&&&&&&&&&&&& View convertView, ViewGroup parent) {
&&&&&&&&&&&& TextView textView = getGenericView();
&&&&&&&&&&&& textView.setText(getChild(groupPosition, childPosition).toString());
&&&&&&&&&&&& return textV
&&&&&&&& }
&&&&&&&& public Object getGroup(int groupPosition) {
&&&&&&&&&&&& return groups[groupPosition];
&&&&&&&& }
&&&&&&&& public int getGroupCount() {
&&&&&&&&&&&& return groups.
&&&&&&&& }
&&&&&&&& public long getGroupId(int groupPosition) {
&&&&&&&&&&&& return groupP
&&&&&&&& }
&&&&&&&& public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
&&&&&&&&&&&&&&&& ViewGroup parent) {
&&&&&&&&&&&& TextView textView = getGenericView();
&&&&&&&&&&&& textView.setText(getGroup(groupPosition).toString());
&&&&&&&&&&&& return textV
&&&&&&&& }
&&&&&&&& public boolean isChildSelectable(int groupPosition, int childPosition) {
&&&&&&&&&&&&
&&&&&&&& }
&&&&&&&& public boolean hasStableIds() {
&&&&&&&&&&&&
&&&&&&&& }
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:408425次
积分:4956
积分:4956
排名:第2096名
原创:94篇
转载:254篇
评论:115条
(6)(9)(14)(14)(7)(3)(2)(2)(13)(1)(3)(1)(6)(2)(4)(3)(13)(1)(3)(4)(8)(9)(5)(2)(8)(18)(7)(3)(19)(29)(36)(10)(32)(1)(3)(2)(22)(23)winform中,如何获得多组动态添加的RadioButton控件的值?
[问题点数:100分,结帖人jshyjyw]
winform中,如何获得多组动态添加的RadioButton控件的值?
[问题点数:100分,结帖人jshyjyw]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
2014年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第四
2014年6月 .NET技术大版内专家分月排行榜第二2014年1月 .NET技术大版内专家分月排行榜第二
2014年2月 .NET技术大版内专家分月排行榜第三2013年4月 .NET技术大版内专家分月排行榜第三
2014年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第四
2014年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第四
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。}

我要回帖

更多关于 android button图片 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信