我正在尝试实现下面图片中的效果,我认为可扩展列表视图可以帮助我,但它并没有起作用。当展开父级时,什么也不显示。
我使用可扩展列表视图做错了吗?有什么其他的选项吗?
请帮帮我。
编辑:适配器类代码:
`public class ExpandableListAdapter extends android.widget.BaseExpandableListAdapter {`
我使用可扩展列表视图做错了吗?有什么其他的选项吗?
请帮帮我。
编辑:适配器类代码:
`public class ExpandableListAdapter extends android.widget.BaseExpandableListAdapter {`
private Activity context;
private List<String> students;
public ExpandableListAdapter(Activity context, List<String> studentIds) {
this.context = context;
this.students = studentIds;
}
public Object getChild(int groupPosition, int childPosition) {
return null;
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String laptop = (String) getChild(groupPosition, childPosition);
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.attendance_view, null);
}
CheckBox isPresent = (CheckBox) convertView.findViewById(R.id.is_present);
EditText absentReason = (EditText) convertView.findViewById(R.id.absent_reason);
return convertView;
}
public int getChildrenCount(int groupPosition) {
return 1;
}
public Object getGroup(int groupPosition) {
return laptops.get(groupPosition);
}
public int getGroupCount() {
return students.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String studentName= (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_item,
null);
}
TextView item = (TextView) convertView.findViewById(R.id.studentIds);
item.setTypeface(null, Typeface.BOLD);
item.setText(studentName);
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}`
final ExpandableListAdapter expListAdapter = new ExpandableListAdapter(Attendance.this, studentIds); expListView.setAdapter(expListAdapter);
- Tushar Agarwal