ExpandableListView显示所有子项

时间:2014-03-01 06:38:41

标签: android android-layout expandablelistview

enter image description here

在这张图片中我有

<ExpandableListView android:id="@+id/recieverList" android:layout_width="fill_parent" android:layout_height="100dp" android:layout_marginBottom="5dp" android:cacheColorHint="@android:color/transparent" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:footerDividersEnabled="false" android:headerDividersEnabled="false" > </ExpandableListView>

当我填充所有子项时,展开只显示“一项”!!! 如何显示所有子项?

“我总是在这个解决方案中有一个具有不同数量的子项目的标题”

这是我的适配器

public class ExpandableNumberAdapter extends BaseExpandableListAdapter {

private Context _context;

ArrayList<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
List<String> List_items;

static int fontSize = 14;

public ExpandableNumberAdapter(Context context) {
    this._context = context;

    listDataHeader = new ArrayList<String>();

    listDataHeader.add(MyActivity.CurrentActivity.getResources().getString(
            R.string.recievers_num));
    // listDataHeader.add(MyActivity.CurrentActivity.getResources().getString(
    // R.string.recievers_num));

    RefreshDB();

    // listDataChild.put(listDataHeader.get(0), goodList);
}

public void RefreshDB() {
    // fontSize = MyActivity.CurrentActivity.GetFontSize();
    List_items = new ArrayList<String>();

    listDataChild = new HashMap<String, List<String>>();

    listDataChild.put(listDataHeader.get(0), List_items);

}

public void RefreshDB(String newNum) {

    List_items.add(newNum);
    notifyDataSetChanged();
}

public static class ChildHolder {
    View CurrentView;
    TextView txt_number;
    Button btn_del;

    public ChildHolder(View view, ExpandableNumberAdapter adapter) {
        Typeface mTypeFace = Typeface.createFromAsset(
                MyActivity.CurrentActivity.getAssets(), "BYekan.ttf");

        txt_number = (TextView) view.findViewById(R.id.txt_number);
        btn_del = (Button) view.findViewById(R.id.btn_del);

        txt_number.setTypeface(mTypeFace);

        txt_number.setTextSize(fontSize);

    }

    public void SetModel(String number) {
        txt_number.setText(number);
    }
}

@Override
public Object getChild(int groupPosition, int childPosititon) {
    return this.listDataChild.get(this.listDataHeader.get(groupPosition))
            .get(childPosititon);
}

@Override
public long getChildId(int groupPosition, int childPosititon) {
    return childPosititon;
}

@Override
public View getChildView(int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    View view = convertView;
    ChildHolder childHolder;
    String item = (String) getChild(groupPosition, childPosition);

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater
                .inflate(R.layout.expand_list_item, null);
        childHolder = new ChildHolder(convertView, this);

        convertView.setTag(childHolder);
    } else {
        childHolder = (ChildHolder) view.getTag();
    }

    childHolder.SetModel(item);
    return convertView;
}

@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 int getGroupCount() {
    return this.listDataHeader.size();
}

@Override
public long getGroupId(int groupPosition) {
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    String headerTitle = (String) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.expand_list_group,
                null);
    }

    return convertView;
}

@Override
public boolean hasStableIds() {
    return false;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

}

0 个答案:

没有答案