详解android 可展开(收缩)的列表ListView(ExpandableListView)
2010-05-11 16:15:00 来源:WEB开发网private List<List<String>> itemList = null;
public IdeasExpandableListAdapter(Context context) {
this.mContext = context;
groupList = new ArrayList<String>();
itemList = new ArrayList<List<String>>();
initData();
}
/**
* 初始化数据,将相关数据放到List中,方便处理
*/
private void initData() {
for (int i = 0; i < groups.length; i++) {
groupList.add(groups[i]);
}
List<String> item1 = new ArrayList<String>();
for (int i = 0; i < familis.length; i++) {
item1.add(familis[i]);
}
List<String> item2 = new ArrayList<String>();
for (int i = 0; i < friends.length; i++) {
item2.add(friends[i]);
}
List<String> item3 = new ArrayList<String>();
for (int i = 0; i < colleagues.length; i++) {
item3.add(colleagues[i]);
}
itemList.add(item1);
itemList.add(item2);
itemList.add(item3);
}
public boolean areAllItemsEnabled() {
return false;
}
/*
* 设置子节点对象,在事件处理时返回的对象,可存放一些数据
*/
public Object getChild(int groupPosition, int childPosition) {
return itemList.get(groupPosition).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
/*
* 字节点视图,这里我们显示一个文本对象
*/
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView text = null;
if (convertView == null) {
text = new TextView(mContext);
更多精彩
赞助商链接