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