GUI를 ExpandableListView
으로 설계했습니다. 아래 샘플 그림을 참조하십시오. 이 상위 그룹에 의존 할 필요없이 목록에있는 모든 아이의 IDs
을 얻을 수있는 경우상위 그룹에 의존하지 않고 ExpandableListView에서 모든 하위 ID를 얻는 방법
나는 알고 싶어요. 내가 얻을 수있어 무엇 현재
첫 번째 부모를위한 0-2이고 두 번째 부모는 0
에서 시작 그래서 기본적으로 내가 같은 ID를 얻으려면 :
- 기구를 ? 이드 (0)
- 칠러? id (1)
- 디스플레이? ID (2)
- "33"내보내기 (수) ID (3) 여기 등
내 Custom adapter
클래스 :
public class MTOExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public MTOExpandableListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int childPosition) {
return childPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_mto_group, null);
}
TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_mto_item, null);
}
TextView txtListChild = (TextView) convertView.findViewById(R.id.lblMTOListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
'BaseExpandableListAdapter' 하위 클래스와 같은 맞춤 어댑터를 사용하고 있습니까? 당신이 그 코드를 게시 할 수 있습니까? 일반적으로 이와 같은 요구 사항이있을 때 어댑터에 비위 재 정의 메소드를 추가하면됩니다. 'getAllChildIds'를 사용하고 그것을 사용하십시오. –
@krislarson 맞춤 어댑터가있는 수업을 참조하십시오. –