WEB开发网
开发学院手机开发Android 开发 详解android 可展开(收缩)的列表ListView(Expan... 阅读

详解android 可展开(收缩)的列表ListView(ExpandableListView)

 2010-05-11 16:15:00 来源:WEB开发网   
核心提示:} else {text = (TextView) convertView;}// 获取子节点要显示的名称String name = (String) itemList.get(groupPosition).get(childPosition);// 设置文本视图的相关属性AbsListView.LayoutParam

} else {

text = (TextView) convertView;

}

// 获取子节点要显示的名称

String name = (String) itemList.get(groupPosition).get(childPosition);

// 设置文本视图的相关属性

AbsListView.LayoutParams lp = new AbsListView.LayoutParams(

ViewGroup.LayoutParams.FILL_PARENT, 40);

text.setLayoutParams(lp);

text.setTextSize(18);

text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);

text.setPadding(45, 0, 0, 0);

text.setText(name);

return text;

}

/*

* 返回当前分组的字节点个数

*/

public int getChildrenCount(int groupPosition) {

return itemList.get(groupPosition).size();

}

/*

* 返回分组对象,用于一些数据传递,在事件处理时可直接取得和分组相关的数据

*/

public Object getGroup(int groupPosition) {

return groupList.get(groupPosition);

}

/*

* 分组的个数

*/

public int getGroupCount() {

return groupList.size();

}

public long getGroupId(int groupPosition) {

return groupPosition;

}

/*

* 分组视图,这里也是一个文本视图

*/

public View getGroupView(int groupPosition, boolean isExpanded,

View convertView, ViewGroup parent) {

TextView text = null;

if (convertView == null) {

text = new TextView(mContext);

} else {

text = (TextView) convertView;

}

String name = (String) groupList.get(groupPosition);

AbsListView.LayoutParams lp = new AbsListView.LayoutParams(

ViewGroup.LayoutParams.FILL_PARENT, 40);

text.setLayoutParams(lp);

text.setTextSize(18);

text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);

上一页  1 2 3 4  下一页

Tags:详解 android 展开

编辑录入:coldstar [复制链接] [打 印]
赞助商链接