Android之ExpandableListView的属性(Group不展开)
来源:互联网 发布:win10如何开启23端口 编辑:程序博客网 时间:2024/04/30 20:34
1. 设置ExpandableListView 默认是展开的:
先实例化exListView 然后
exListView.setAdapter(exlvAdapter); //遍历所有group,将所有项设置成默认展开 intgroupCount = exListView.getCount(); for (inti=0; i<groupCount; i++) { exListView.expandGroup(i); };
2. 去掉ExpandableListView 默认的箭头
用到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下:
settingLists.setGroupIndicator(null); ~~~~~~~~~~~~~~~~~此处就是设置自定义的箭头图标的。置空则没有了。
也可以自定义(但是位置还是在那个地方不推荐)如下:
首先,自定义一个expandablelistviewselector.xml文件,具体内容如下: Java代码
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_expanded="true" android:drawable="@drawable/expandablelistviewindicatordown" /> <item android:drawable="@drawable/expandablelistviewindicator" /> </selector>
加一句代码如下:
settingLists.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector)); 或xml设置:android:groupIndicator="@drawable/groupIndicator_selector"
大功告成
1首先ExpandableListViewelistview;
elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉,
2在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法
/** * 父类view */ @Override public View getGroupView(intgroupPosition, booleanisExpanded, View convertView, ViewGroup parent) { Log.i("zhaoxiong","parent view"); LinearLayoutparentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null); TextViewparentTextView=(TextView)parentLayout.findViewById(R.id.parentitem); parentTextView.setText(parentlist.get(groupPosition)); ImageViewparentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow); //判断isExpanded就可以控制是按下还是关闭,同时更换图片 if(isExpanded){ parentImageViw.setBackgroundResource(R.drawable.arrow_down); }else{ parentImageViw.setBackgroundResource(R.drawable.arrow_up); } return parentLayout; }
expandablelistview响应onGroupClick监听:设置expandablelistview.setOnGroupClickListener()
折叠和展开事件,可以设置setOnGroupCollapseListener和setOnGroupExpandListener
ExpandableListView中包含多个group,想要展开一个group时,其他group都关闭:
exList.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { for (int i = 0; i < getData().size(); i++) { if (groupPosition != i) { exList.collapseGroup(i); } } } });3.expandablelistview的Group点击事件,onGroupClick的返回值false展开,true不展开
tt_list.setOnGroupClickListener(new OnGroupClickListener() {@Overridepublic boolean onGroupClick(ExpandableListView parent, View v,int groupPosition, long id) {IsFlag=true;if(adapter.getGroupData().get(groupPosition).getList().size()==1){Bundle b=new Bundle();b.putInt("saveIndex", 0);//b.putString("mac", mac);//b.putString("deviceId", mDeviceId);b.putSerializable("datalist", adapter.getGroupData().get(groupPosition).getList());Intent i=new Intent(WappushBindingActivity.this,VideoPlayerActivity.class);i.putExtras(b);startActivity(i);}//int groupCount = tt_list.getCount(); //for (int i=0; i<groupCount; i++){ //if(i!=GroupPosition)//tt_list.collapseGroup(i); // }; //Log.v("xulongheng*WappushBind*tt_list", "onGroupClick:"+previousX+"/"+previousY);return true; //默认为false,设为true时,点击事件不会展开Group}});
- Android之ExpandableListView的属性(Group不展开)
- Android之ExpandableListView的属性(Group不展开)
- Android之ExpandableListView的属性(Group不展开)
- Android之ExpandableListView的属性(Group不展开)
- Android之ExpandableListView的属性(Group不展开)
- Android之ExpandableListView的属性(展开,闭合,箭头)
- ExpandableListView 功能界面布局探究之三(没有child的下拉列表,group不展开的实现)
- ExpandableListView 功能界面布局探究之二(只展开一个group的实现)
- ExpandableListView的首次加载全部展开,并且点击Group不收缩,去掉Group左边的箭头
- Android之带group指示器的ExpandableListView
- Android之带group指示器的ExpandableListView
- Android之带group指示器的ExpandableListView
- 跪求大神!!!探讨android ExpandableListView group展开后如何不出屏幕
- ExpandableListView展开所有Group
- android之ExpandableListView 无法展开
- ExpandableListView的首次加载全部展开,并且点击Group不收缩、
- ExpandableListView的首次加载全部展开,并且点击Group不收缩、
- ExpandableListView的首次加载全部展开,并且点击Group不收缩
- 第四讲 HTML5 Canvas 画图标签 & 画线,圆,渐变色
- 6.1
- 如何将路由器当作交换机使用?
- Android中的音频播放(MediaPlayer和SoundPool)
- scanf与printf用法详解
- Android之ExpandableListView的属性(Group不展开)
- Understanding and using c pointers 第三章读书笔记
- c++拷贝构造函数
- viewPager控制滑动速度和时间
- [Django实战] 第4篇 - 用户认证(用户登录与注销)
- linux常见问题之vim 查找替换命令
- epoll
- 小例子大智慧1---C#继承,构造函数
- UltraEdit 中用正则表达式替换文本中的空行