Android之ExpandableListView的属性(Group不展开)
2016-01-20 16:27
621 查看
Android之ExpandableListView的属性(Group不展开)
1. 设置ExpandableListView 默认是展开的:
先实例化exListView 然后
[java] view
plain copy
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代码
[html] view
plain copy
<?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>
加一句代码如下:
[java] view
plain copy
settingLists.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector));
或xml设置:
android:groupIndicator="@drawable/groupIndicator_selector"
大功告成
3. 将默认的箭头修改到右边显示:
1首先ExpandableListViewelistview;
elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉,
2在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法
[java] view
plain copy
/** * 父类view */ @Override
ublic 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都关闭:
[java] view
plain copy
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不展开
[java] view
plain copy
tt_list.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public 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
}
});
转载:/article/2598657.html
1. 设置ExpandableListView 默认是展开的:
先实例化exListView 然后
[java] view
plain copy
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代码
[html] view
plain copy
<?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>
加一句代码如下:
[java] view
plain copy
settingLists.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector));
或xml设置:
android:groupIndicator="@drawable/groupIndicator_selector"
大功告成
3. 将默认的箭头修改到右边显示:
1首先ExpandableListViewelistview;
elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉,
2在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法
[java] view
plain copy
/** * 父类view */ @Override
ublic 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都关闭:
[java] view
plain copy
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不展开
[java] view
plain copy
tt_list.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public 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
}
});
转载:/article/2598657.html
相关文章推荐
- Android自定义控件:Android L控件点击水波纹的实现(源码 + Demo)
- Android 自定义圆形进度条
- Android USB HOST通信
- Android 四大组件详解(一) Activity
- Android5.0材料设计(三)
- Android 实现个性的ViewPager切换动画 实战PageTransformer(兼容Android3.0以下
- Android开发相关工具等资源快速查找地址
- Android 4.4 状态栏背景
- Android中JNI的使用方法
- I.MX6 android 获取framebuffer信息
- Android 开源框架ActionBarSherlock 和 ViewPager 仿网易新闻客户端
- Android访问C#的WebService要注意的问题
- Android测试
- android shape讲解小全及例子
- Android XML file之animation-list
- Android hdpi ldpi mdpi xhdpi xxhdpi适配详解
- Android input ascii only
- Android自定义异常处理
- Android 事件分发机制 理解杂谈
- Android初学习 - Android系统自带样式(android:theme)