我想自定義視圖添加到組視圖與BaseExpandableListAdapterAndroid的自定義視圖和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);
}
}
infopanel.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;
}
........
代碼工作(即不拋出任何異常),但不顯示視圖。
你知道嗎爲什麼?
感謝和問候
我是正確的...但我想維持一個局部變化我的看法...因爲我有其他視圖控制它,,,像editText和其他類型的輸入控件...我需要來控制我的視圖是否爲空,而不是convertview – 2011-02-16 10:00:32