我想使用 BaseExpandableListAdapter 将自定义视图添加到组视图
这是代码:
自定义视图和 layout.xml
public class InfoView extends View{
private EditText nameEditText;
private EditText descriptionEditText;
private Spinner goalTypeSpinner;
private Spinner categorySpinner;
Button addGoalCategoryButton;
public InfoView(Context context) {
super(context);
inflate(context, R.layout.info_panel, parent);
nameEditText = (EditText) findViewById(R.id.nameEditText);
descriptionEditText = (EditText) findViewById(R.id.descriptionEditText);
goalTypeSpinner = (Spinner)
findViewById(R.id.goalTypeSpinner);
categorySpinner = (Spinner)
findViewById(R.id.categorySpinner);
}
}
信息面板.xml
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" >
<Spinner android:id="@+id/goalTypeSpinner" android:prompt="@string/goalType"
android:entries="@array/goalTypeList" style="@style/commonText.commonSpinner" >
</Spinner>
<TableRow style="@style/commonText.commonTableRow">
<Spinner android:id="@+id/categorySpinner" style="@style/commonText.commonSpinner.right"
android:prompt="@string/goalType">
</Spinner>
<Button android:id="@+id/newCategoryButton" style="@style/commonText.commonButton"
android:text="add category" />
</TableRow>
<EditText android:id="@+id/nameEditText" android:hint="@string/nameEditTextHint"
style="@style/commonText.commonEditText" >
</EditText>
<EditText android:id="@+id/descriptionEditText" android:hint="@string/descriptionEditTextHint"
style="@style/commonText.commonTextArea">
</EditText>
</LinearLayout>
在 BaseExpandableListAdapter 中:
..............
InfoView infoView;
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (group.equals(INFO) && child.equals(INFO)) {
Log.i(TAG, "group INFO(" + group + ")");
if (infoView == null) {
// i don't want to recreate everytime
// the view so i check if is null
infoView = new InfoView(context);
}
return infoView;
}
........
代码工作(即不抛出任何异常),但视图不显示。
你知道为什么吗 ?
谢谢并恭祝安康