读书人

Android 之ExpandableListView几个非一

发布时间: 2012-09-10 11:02:33 作者: rapoo

Android 之ExpandableListView几个特殊的属性

1. 设置ExpandableListView 默认是展开的:

先实例化 exListView

然后

exListView.setAdapter(exlvAdapter);

//遍历所有group,将所有项设置成默认展开

int groupCount = exListView.getCount();

for (int i=0; i<groupCount; i++) {

exListView.expandGroup(i);

};


2. 去掉ExpandableListView 默认的箭头

用到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下:

settingLists.setGroupIndicator(null); ~~~~~~~~~~~~~~~~~此处就是设置自定义的箭头图标的。置空则没有了。


也可以自定义(但是位置还是在那个地方不推荐)如下:

首先,自定义一个expandablelistviewselector.xml文件,具体内容如下:
Java代码

<?xml version=

1首先 ExpandableListView elistview;

elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉,

2在 自定义的继承自BaseExpandableListAdapter的adapter中有一个方法

/**
* 父类view
*/
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Log.i("zhaoxiong","parent view");
LinearLayout parentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null);
TextView parentTextView=(TextView) parentLayout.findViewById(R.id.parentitem);
parentTextView.setText(parentlist.get(groupPosition));
ImageView parentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow);

//判断isExpanded就可以控制是按下还是关闭,同时更换图片
if(isExpanded){
parentImageViw.setBackgroundResource(R.drawable.arrow_down);
}else{
parentImageViw.setBackgroundResource(R.drawable.arrow_up);
}

return parentLayout;
}





3楼zhai1231昨天 20:57
写的不错 顶一下 Mr.PhD
2楼zhai123l昨天 19:03
我再补充点 小点细节n如果需要实现 子条目点击事件 在适配器中复写 n[code=java]npublic boolean isChildSelectable(int groupPosition, int childPosition) { n // TODO Auto-generated method stub n return true; n } n[/code]n和设置事件n[code=java]nExpandableListView().setOnChildClickListener(new OnChildClickListener() {nn@Overridenpublic boolean onChildClick(ExpandableListView parent, View v,nint groupPosition, int childPosition, long id) {}n[/code]nnn想让界面更加的人性化,就要实现很多的效果,比如只展开一个group,在点击下个group的同时,关闭之前的groupnn在一个ExpandableListView,如何实现只展开一个group,方法如下:n[code=java]n final ExpandableListView mExpandableListView= getExpandableListView();ntt mExpandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {ntttnttt@Overridentttpublic void onGroupExpand(int groupPosition) {ntttt for(int i=0;i<group.size();i++){nt if(groupPosition != i){nt tmExpandableListView.collapseGroup(i);nt }nt }nttttnttt}ntt});n[/code]
1楼ihrthk3天前 08:47
东西有点少,最好来个ExpandableListView详解。
Re: t12x3456前天 15:47
这几个属性时我最近做的时候遇到的一些细节问题,详解的话你可以自己搜资料或者看sdk文档,解释比较全

读书人网 >Android

热点推荐