Having 2 empty layout components when list is empty
When my Listview contains no items I have set 2 empty layoutcomponents in my XML. Is it possible to address either one of these components in code? Because the button has to be below the TextView, but when it's not in XML, the app crashes because it finds the TextView first.
My XML looks like this:
<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开发者_Go百科="Er zijn geen jobs die voldoen aan uw criteria..."
android:gravity="center"/>
Update: with following code it runs perfectly, but the button is not shown...
<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>
Just put the Button and the TextView into a LinearLayout
<LinearLayout android:id="@android:id/empty">
<Button />
<TextView />
</LinearLayout>
精彩评论