我正在使用自定義listView。 這裏是我的代碼:頁腳和標題是不是在Android ListView中添加 - 一個錯誤修復
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
viewInit();
adapter = new myPlanAdapter(this);
LayoutInflater inflater = this.getLayoutInflater();
LinearLayout listFooterView = (LinearLayout) inflater.inflate(
R.layout.violet_footer, null);
listView.addFooterView(listFooterView);
LinearLayout listHeaderView = (LinearLayout) inflater.inflate(
R.layout.blue_header, null);
listView.addHeaderView(listHeaderView);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
,這裏是我的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="@drawable/head"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="9"
android:gravity="center"
android:text="My Exam"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/AddMyPlanButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add" />
</LinearLayout>
<ListView
android:cacheColorHint="@android:color/transparent"
android:id="@+id/myPlanListViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
</LinearLayout>
這裏是footer.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="@drawable/trans_violet_half_round"
android:orientation="vertical" >
</LinearLayout>
我缺少什麼?頁眉和頁腳未添加。
您可以添加頁眉或頁腳佈局定義嗎?也許問題是時間的高度... – Selvin 2012-02-29 07:42:20
@selvin頁腳佈局也添加了。 – asish 2012-02-29 07:58:51