Skip to content Skip to sidebar Skip to footer

Android Listview With Complex Header

I'm trying to add a complex / non-trivial header to a ListView (and slightly less complex footer) that needs to scroll along with the rest of the content. The header consists of

Solution 1:

I've attempted to reimplement my scrolling listview from scratch, roughly as follows:

  • a main.xml with a background image and a single ListView, with a 20dip margin and some specific styling:

    <itemname="android:cacheColorHint">#00000000</item><itemname="android:scrollbars">@null</item><itemname="android:background">@android:color/transparent</item>
  • a headerlayout.xml containing a linear layout (vertical), containing a TextView, ImageView and another TextView. The first TextView is styled with rounded topcorners, both textviews are styled transparent, and a clicklistener on the image.

  • (a similarly styled footer)
  • a custom entry for each listitem with a solid white background.

The header/footer are added roughly as follows

ListViewlist= (ListView) findViewById(R.id.list);
Viewheader1=  getLayoutInflater().inflate(R.layout.listheader, null, false);
Viewfooter= getLayoutInflater().inflate(R.layout.listfooter, null, false);
ImageViewimage= (ImageView) header1.findViewById(R.id.image);

list.addHeaderView(header1, null, false);
list.addFooterView(footer, null, false);
list.setAdapter(newMenuAdapter());

None of this is actually truely special. It's mostly a matter of doing things in the right order, stripped down and properly styled.

Solution 2:

My suggestion would be that you create a custom view for this overly complicated list view item. Apparently this is what Android devs at Google IO too suggested. If you can do it in custom view, all your problems will be solved for.

Post a Comment for "Android Listview With Complex Header"