您可以使用 Expendable 列表,它允许您显示组和子组的种类。为此,您需要创建一个 BaseExpandableListAdapter。你需要重写这个类的两个方法。
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.group_row, null);
}
//TextView tv=new TextView(context);
TextView tv = (TextView) convertView.findViewById(R.id.tvGroupName);
//tv.setText(parentList[groupPosition]);
tv.setText(category_list.get(groupPosition).toString());
//tv.setPadding(70,0,0,10);
//return tv;
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_row, null);
}
//TextView tv=new TextView(context);
TextView tv = (TextView) convertView.findViewById(R.id.tvPlayerName);
//tv.setText(childList[groupPosition][childPosition]);
tv.setText((String)((ArrayList)sub_category_list.get(groupPosition)).get(childPosition));
//tv.setPadding(70,0,0,10);
//return tv;
return convertView;
}