4

我不知道为什么我的可扩展组件多次调用 getChildView() 和 getGroupView()。该问题会影响应用程序的性能。请帮帮我,这是这个适配器。

public class ResultsExpandableAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ArrayList<TraceGroupObject> groups;
private int displayMode;
private String TAG = "EXPAND LIST NUTRIENT";

public ResultsExpandableAdapter(Context context,
        ArrayList<TraceGroupObject> groups, int displayMode) {
    this.mContext = context;
    this.groups = groups;
    this.displayMode = displayMode;
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    ArrayList<TraceObject> group = groups.get(groupPosition).getItems();
    return group.get(childPosition);
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return childPosition;
}

代码getChildView

// bug
@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    // Log.i(TAG, "Child View (" + groupPosition + "," + childPosition
    // + ") ->" + convertView);
    final TraceObject trace = (TraceObject) getChild(groupPosition,
            childPosition);
    View row;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.expandable_row_item, null);
        // Log.i(TAG, "Created View ->" + convertView);
    } else
        row = convertView;

    // init tracebar
    ...

    // implement
    return row;
}

嗨嗨嗨

@Override
public int getChildrenCount(int groupPosition) {
    ArrayList<TraceObject> rows = groups.get(groupPosition).getItems();
    return rows.size();
}

@Override
public Object getGroup(int groupPosition) {
    // TODO Auto-generated method stub
    return groups.get(groupPosition);
}

@Override
public int getGroupCount() {
    // TODO Auto-generated method stub
    return groups.size();
}

@Override
public long getGroupId(int groupPosition) {
    // TODO Auto-generated method stub
    return groupPosition;
}

ac ac getGroupView

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    // Log.i(TAG, "Group View "+groupPosition +"->" +convertView);
    TraceGroupObject group = (TraceGroupObject) getGroup(groupPosition);

    // create view
    View row;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.expandable_group_item, null);
        // Log.i(TAG, "Created View ->" +convertView);
    } else
        row = convertView;

    // change icon expand
    ...

    return row;
}

@Override
public boolean hasStableIds() {
    // TODO Auto-generated method stub
    return true;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return false;
}
4

0 回答 0