-1

Assumptions about the list (updated):

  • It will not contain more than 10 list elements (the list elements are defined by the xml layout below).
  • The height of every element is unknown, because the list element contain a LinearLayout that can have up to 20 child views (see xml below).

XML Layout of the list element:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation:"horizontal">

    <!--
        This LinearLayout is going to contain one or more 
        Views which will be added progammatically on runtime.
        The number of children views added to it depend on the 
        data to be displayed, and the only assumption that can 
        be made is that there's will be no more than 20 child 
        views for one particular instance of this LinearLayout.
    -->
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginRight="25dp"/>

    <ImageButton
        android:layout_width="25dip"
        android:layout_height="25dip"
        android:layout_gravity="center|top"
        android:layout_marginLeft="-25dp"/>
</LinearLayout>

Questions:

  • Does it make any sense to use a ListView for a layout that has such freedom in its structure (like the one above), and still being able to make use of the
    convertView as passed in to the ListView#getView(...)?
  • As an alternative, would it be wrong to put all the list elements in an outer
    LinearLayout and put this within a ScrollView? By doing this, I wouldn't get caching abilities of the ListView, but maybe it wouldn't be so heavy given the assumptions about the list? (see top). (Any pointers on how to make this alternative look and feel like a ListView? I'm thinking of applying standard colors and selectors etc.)
Håvard Geithus
  • 5,544
  • 7
  • 36
  • 51
  • When I tried to construct a view dynamically by adding views/removing them, the listview threw an expception. So not sure you could do what you want i.e. dynamically add views, when you are trying to recycle the view. – Prakash Nadar Dec 30 '11 at 15:14

1 Answers1

1

If you know some of your 10 elemets will be the same, you could use

getItemViewType(int position)

To be sure that the convertView will match your item type convertView

vieux
  • 23,887
  • 3
  • 26
  • 26
  • Differentiating on view types turned out to be the most efficient approach in my particular case. It made it possible to keep the view hierarchy small :) – Håvard Geithus Jan 04 '12 at 15:57