Android 如何在可展开列表视图中将按钮设置为子布局而不是字符串

Android 如何在可展开列表视图中将按钮设置为子布局而不是字符串,android,listview,Android,Listview,我遵循了这个教程。在该教程中,子布局设置为字符串格式,但这里我需要直接设置布局,而不是创建字符串 这是我的子布局代码,它有三个按钮是,否,可能和一个复选框 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/hidden" android:layout_width="0dp" android:layout_height="50dp"

我遵循了这个教程。在该教程中,子布局设置为字符串格式,但这里我需要直接设置布局,而不是创建字符串

这是我的子布局代码,它有三个按钮是,否,可能和一个复选框

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hidden"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:layout_marginLeft="-270dp"
    android:layout_marginTop="60dp"
    android:layout_weight="1"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="horizontal"
    android:paddingTop="1dp"
    android:visibility="gone"
    android:weightSum="3">


    <Button
        android:id="@+id/yesButton"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="7dp"
        android:layout_weight="1"
        android:background="@color/lightgray"
        android:text="Yes"
        android:textColor="@color/black"></Button>

    <Button
        android:id="@+id/noButton"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="25dp"
        android:layout_weight="1"
        android:background="@color/lightgray"
        android:text="No"
        android:textColor="@color/black"></Button>

    <Button
        android:id="@+id/buttonMayBe"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:background="@color/lightgray"
        android:text="Maybe"
        android:textColor="@color/black"></Button>


    <CheckBox
        android:id="@+id/invitationCheckBox"
        android:layout_width="@dimen/check_box_width"
        android:layout_height="50dp"
        android:button="@drawable/selector"
        android:focusable="true"
        android:scaleX="0.5"
        android:scaleY="0.5" />

</LinearLayout>

可扩展列表视图

public class ExpandableAdapter  extends BaseExpandableListAdapter {

private Context _context;
ArrayList<Group> list;

public ExpandableAdapter(Context context, ArrayList<Group> list) {
    this._context = context;
   this.list = list;
}

@Override
public Object getChild(int groupPosition, int childPosititon) {
    return list.get(groupPosition).getMembers().get(childPosititon);

}

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

@Override
public View getChildView(int groupPosition, final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {



    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.expand_child, null);
    }

    TextView txtListChild = (TextView) convertView.findViewById(R.id.text1);

    txtListChild.setText(list.get(groupPosition).getMembers().get(childPosition).getName());
    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
     return list.get(groupPosition).getMembers().size();
}

@Override
public Object getGroup(int groupPosition) {
     return list.get(groupPosition);
}

@Override
public int getGroupCount() {
     return list.size();
}

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

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(android.R.layout.simple_expandable_list_item_2, null);
    }

    TextView lblListHeader = (TextView) convertView
            .findViewById(android.R.id.text1);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    lblListHeader.setText(list.get(groupPosition).getGroupName());

    return convertView;
}

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

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}
公共类ExpandableAdapter扩展了BaseExpandableListAdapter{
私人语境(private Context)(私人语境);;
数组列表;
公共可扩展适配器(上下文、ArrayList列表){
这._context=context;
this.list=列表;
}
@凌驾
公共对象getChild(int-groupPosition、int-ChildPosition){
返回list.get(groupPosition.getMembers().get(childpositionon);
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回子位置;
}
@凌驾
公共视图getChildView(int groupPosition,final int childPosition,
布尔值isLastChild、视图转换视图、视图组父级){
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.\u上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(R.layout.expand_child,null);
}
TextView txtListChild=(TextView)convertView.findViewById(R.id.text1);
txtListChild.setText(list.get(groupPosition.getMembers().get(childPosition.getName());
返回视图;
}
@凌驾
公共整数getChildrenCount(整数组位置){
返回list.get(groupPosition.getMembers().size();
}
@凌驾
公共对象getGroup(int-groupPosition){
返回列表。获取(groupPosition);
}
@凌驾
public int getGroupCount(){
返回list.size();
}
@凌驾
公共长getGroupId(int-groupPosition){
返回组位置;
}
@凌驾
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.\u上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.flate(android.R.layout.simple\u expandable\u list\u item\u 2,null);
}
TextView lblistheader=(TextView)convertView
.findviewbyd(android.R.id.text1);
lblListHeader.setTypeface(null,Typeface.BOLD);
lblistheader.setText(list.get(groupPosition.getGroupName());
返回视图;
}
@凌驾
公共布尔表ID(){
返回false;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
返回true;
}

}

在getchildview()中为该布局充气。请添加代码。。