今天在项目中要实现一个可以展开的列表,我首先想到的就是android的ExpandableListView,这个使用起来还是挺方便的,可以对ListView进行收放。现在直接上代码吧。
在布局文件中添加 ExpandableListView
Activity中的代码
public class MainActivity extends ActionBarActivity {
private ExpandableListView exp_listview;
private List gourp_list=new ArrayList();
private List
适配器的编写,这里编写适配器继承的是BaseExpandableListAdapter。
public class ExpandAdapter extends BaseExpandableListAdapter{
private List gourp_list;
private List
在编写适配器的时候要注意一些问题:
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
/**
* 返回值为false 不响应子条目的点击
*/
return true;
}
返回值要为true,否则,点击子条目的时候没有反应。
group_item代码
bluetooth_child_tiem代码