我遵循了本教程http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/。在该教程中,子布局设置为字符串格式,但在这里我需要直接设置布局而不是创建字符串。
这是我的子布局代码,有三个按钮是,否,可能和复选框。
<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>
答案 0 :(得分:0)
可扩展listview adpater
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;
}
}