2
當我的列表視圖不包含項目時,我在XML中設置了2個空佈局組件。是否有可能在代碼中解決這些組件中的任何一個?由於該按鈕必須位於TextView下方,但當它不在XML中時,該應用程序會因爲首先找到TextView而崩潰。當列表爲空時,有2個空佈局組件
我的XML看起來是這樣的:
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
<Button
android:id="@android:id/empty"
android:layout_margin="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toon dichtstbijzijnde kantoor"
android:gravity="center"/>
<TextView android:layout_height="wrap_content"
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:text="Er zijn geen jobs die voldoen aan uw criteria..."
android:gravity="center"/>
更新: 與下面的代碼運行完美,但按鈕不顯示...
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
<LinearLayout android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView android:layout_height="wrap_content"
android:id="@+id/TestText"
android:layout_width="fill_parent"
android:text="Er zijn geen jobs die voldoen aan uw criteria..."
android:gravity="center"/>
<Button
android:id="@+id/Test"
android:layout_margin="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toon dichtstbijzijnde kantoor"
/>
</LinearLayout>
我把它作爲一個樣本,你必須填寫佈局屬性,例外是告訴你一切 - java.lang.RuntimeException:二進制XML文件行#46:你必須提供一個layout_width屬性。 – BFil 2011-05-18 13:56:44
這對我來說很愚蠢。謝謝。但是,現在我已經替換了TextView下面的按鈕,並給了他'android:id =「@ + id/Test」'沒有顯示。只顯示TextView(也有另一個ID爲空)。 – Hannelore 2011-05-18 14:01:00
不要放任何其他元素爲ID「@android:id/empty」,只是佈局 – BFil 2011-05-18 14:02:33