views:

80

answers:

1

Hi,

Im trying to have a searchbox on the top of my list view. But I want this searchbox to disapear sometimes and the listview to resize to regain space. Is there a way I can do that without reloading another and different layout ???

is there a way to add and remove a component from the current view ?I have been playing with setvisibility but it doesnt resize anything.

Please, if you know, give code example ! :)

+2  A: 

I did this with a layout like this

<RelativeLayout android:id="@+id/editFrame"
    android:layout_width="wrap_content"
    android:layout_below="@id/imageAttachments"
    android:layout_height="wrap_content"
    >

    <EditText android:id="@+id/editText"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        ></EditText>
</RelativeLayout>

<ListView android:id="@+id/ListView01"
    android:layout_below="@id/editFrame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    ></ListView>

Then, in the code, do the following:

findViewById(R.id.editText).setVisibility(View.GONE);

to free up the space, or

findViewById(R.id.editText).setVisibility(View.VISIBLE);

to show the search box. Instead of the EditText, one can as well use any other single control or a layout for a combination of controls. Setting its visibility to GONE will make the surrounding editFrame layout (can as well be a FrameLayout) shrink to zero size and reclaim the space for the ListView (which is set to be layout directly below the editFrame layout).

Thorstenvv
You just save my life ! :)))
Fabien