我在我的项目中实现了n级可消耗列表,但是我无法找到内部消耗列表的实际大小。例如,第一级消耗性列表有4个孩子它显示正确当我点击第一级项目他们又有4个孩子,但我只能看到2或3个孩子。我和你分享我的代码,请帮助我。
这是我的ExpandableListAdapter类:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
Context context;
LinkedHashMap objhashTable;
public ExpandableListAdapter(Context con, LinkedHashMap objhashTable) {
// TODO Auto-generated constructor stub
this.context = con;
this.objhashTable = objhashTable;
Log.i("ParentView", "objhashTable == " + objhashTable.size());
// nu
}
@Override
public Object getChild(int arg0, int arg1) {
return arg1;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
//Log.i("ParentView", "getChildView == " + childPosition
// + " groupPosition == " + groupPosition+" parent == "+conve);
//parent.
LinkedHashMap temp = getSelectedObject(groupPosition);
if (temp != null && getSelectedObject(groupPosition) != null ) {
ExpandableListAdapter parebnt = new ExpandableListAdapter(context, temp);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.expendablelist, parent, false);
ExpandableListView NextLevelAdapter =(ExpandableListView)convertView.findViewById(R.id.ParentLevel123);
TextView txt = (TextView)convertView.findViewById(R.id.txtLevel);
txt.setText(getSelectedKey(groupPosition) );
txt.setTextColor(Color.BLACK);
txt.setTag(getSelectedKey(groupPosition));
txt.setTextSize(20);
txt.setBackgroundColor(Color.BLUE);
txt.setPadding(10, 7, 7, 7);
//CustExpListview SecondLevelexplv = new CustExpListview(context);
NextLevelAdapter
.setAdapter(/* new SecondLevelAdapter(context) */parebnt);
NextLevelAdapter.setGroupIndicator(null);
convertView.measure( MeasureSpec.AT_MOST, MeasureSpec.AT_MOST );
convertView.getLayoutParams().height = convertView.getMeasuredHeight();
return convertView;
}else{
return null;
}
}
@Override
public Object getGroup(int groupPosition) {
return groupPosition;
}
@Override
public int getGroupCount() {
//if (objhashTable != null )
//Log.i("ParentLevel", "objhashTable == "+objhashTable);
return objhashTable.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
private LinkedHashMap getSelectedObject(int groupPos) {
LinkedHashMap lnmap = null;
if (objhashTable != null) {
Iterator it = objhashTable.keySet().iterator();
int i = 0;
while (it.hasNext()) {
String type = (String) it.next();
if (i == groupPos) {
lnmap = (LinkedHashMap) objhashTable.get(type);
// childCount =lnmap.size();
break;
}
i++;
}
}
return lnmap;
}
private String getSelectedKey(int groupPos) {
String type = null;
if (objhashTable != null) {
Iterator it = objhashTable.keySet().iterator();
int i = 0;
while (it.hasNext()) {
type = (String) it.next();
if (i == groupPos) {
// lnmap = (LinkedHashMap)objhashTable.get(type);
// childCount =lnmap.size();
break;
}
i++;
}
}
return type;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 1;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return null;
}
}