ExpandableListView

 //创建一个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);
}


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