0

How can I remove entire RelativeLayout which is added as header to my another layout. Here is my code:

tour.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/relativeVideoTour"
    android:layout_height="232dp" >

    <ImageButton
        android:id="@+id/play_button1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:background="@drawable/video_img"
        android:contentDescription="@null" />

    <ImageButton
        android:id="@+id/play_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/play"
        android:contentDescription="@null" />

</RelativeLayout>

I added this layout to my list view.

ListView m_listView = (ListView) listView.findViewById(R.id.list);
m_listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.tour, null));
        m_listView.setHeaderDividersEnabled(false);

        m_relativeVideoTour = (RelativeLayout) listView.findViewById(R.id.relativeVideoTour);

        m_relativeVideoTour.setVisibility(View.INVISIBLE);
        m_relativeVideoTour.setVisibility(View.GONE);

By using above code, images of those buttons in tour.xml are not shown .. but the white space still maintain on the top of the list.

How can I remove entire layout of tour with white space(want to show only listview)

Please help me.. Thanks in advance...

Lokesh
  • 5,180
  • 4
  • 27
  • 42

3 Answers3

1

If you want to remove the header from the list you should use this code:

m_listView.removeHeaderView(m_relativeVideoTour);

Where m_relativeVideoTour should be the view which is ListView's header.

But when you use removeHeaderView() to remove the header you can't add it again because you can only add the header before setting the listAdapter.

I would advise you to follow the workaround mentioned here: Remove header from listView

Community
  • 1
  • 1
maclir
  • 3,218
  • 26
  • 39
  • Hey thanks it's working.. but, when I want to add same header some other place. I used m_listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.take_tour_header, null)); m_listView.setHeaderDividersEnabled(false); and it throws illaglestateException – Lokesh Jul 13 '13 at 14:17
  • Error: 07-13 08:21:17.642: E/AndroidRuntime(22093): java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called. – Lokesh Jul 13 '13 at 14:46
  • Added an edit regarding this. Apparently you can't add the header once you removed it since you can only add a header before setting the listAdapter, but there is a work around which I gave the link to in the answer. – maclir Jul 13 '13 at 19:38
-1

i don't know whether its right or not but it should work, so you can try by adding extra code in your java file :

ImageButton ib=(ImageButton)findViewById(R.id.play_button);
ib.setVisibility(View.GONE);

ImageButton ib1=(ImageButton)findViewById(R.id.play_button1);
ib1.setVisibility(View.GONE);

its Visibility must be set to be GONE because by using invisible it becomes invisible but it doesn't leave its space !

Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
-1

since you use listView, you should use removeHeaderView on the view that you've inflated.

btw, you should not mess with the views that the listView contains, unless you know exactly what you're doing.

instead (and in this case only), just keep a reference to this special view.

android developer
  • 114,585
  • 152
  • 739
  • 1,270