码迷,mamicode.com
首页 > 其他好文 > 详细

ExpandableListView

时间:2015-09-17 17:37:21      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

 //创建一个BaseExpandableListAdapter对象
ExpandableListAdapter adapter = new BaseExpandableListAdapter()
{

public Object getChild(int groupPosition, int childPosition)
{
return arms[groupPosition][childPosition];
}

@Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}

@Override
public int getChildrenCount(int groupPosition)
{
return arms[groupPosition].length;
}

private TextView getTextView()
{
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 64);
TextView textView = new TextView(MainActivity.this);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
textView.setPadding(36, 0, 0, 0);
textView.setTextSize(20);
return textView;
}


// 该方法决定每个子选项的外观
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
TextView textView = getTextView();
textView.setText(getChild(groupPosition, childPosition)
.toString());
return textView;
}


// 获取指定组位置处的组数据
@Override
public Object getGroup(int groupPosition)
{
return armTypes[groupPosition];//设置显示数据1
}
@Override
public int getGroupCount()
{
return armTypes.length;//设置组长度
}
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;//设置组位置
}


/*******************************设置可改*****************************************/
// 该方法决定每个组选项的外观
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
LinearLayout ll = new LinearLayout(MainActivity.this);
ll.setOrientation(0);
ImageView logo = new ImageView(MainActivity.this);
logo.setImageResource(logos[groupPosition]);
ll.addView(logo);
TextView textView = getTextView();
textView.setText(getGroup(groupPosition).toString());
ll.addView(textView);
return ll;
}
/*************************************8*************************************************/

@Override
public boolean isChildSelectable(int groupPosition,
int childPosition)
{
return true;
}
@Override
public boolean hasStableIds()
{
return true;
}
};
ExpandableListView expandListView = (ExpandableListView) findViewById(R.id.list);
expandListView.setAdapter(adapter);
}


ExpandableListView

标签:

原文地址:http://www.cnblogs.com/yhc04161120/p/4816805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!