On Sun, Sep 18, 2011 at 2:53 PM, John Goche <[email protected]> wrote:
> Yes, the example can be modified to do more or less what I wanted. Here is
> what I changed:
>
> inside getView in Main.java:
> =======================================================================
>
>             }else{
>                 row = inflater.inflate(R.layout.list_row_layout_odd, parent,
> false);
>               TextView textLabel = (TextView) row.findViewById(R.id.text);
>                 TextView textLabel2 = (TextView)
> row.findViewById(R.id.text2);
>                 textLabel.setText(data[position]);
>                 textLabel2.setText(data[position]);
>             }
>
>             return (row);
>         }
> ==========================================================
>
> Then at the bottom of row_layout_odd.xml inside the relative layout:
>
>   <TextView android:id="@+id/text2"
>     android:layout_height="wrap_content"
>     android:layout_width="wrap_content"
>     android:layout_alignParentLeft="true"
>     android:textColor="#ffffff"
>     android:textSize="16dip"
>     android:layout_marginRight="120dip"
>     android:layout_marginLeft="8dip"
>     android:layout_marginTop="30dip" />
>
> ==========================================================
>
> I am still curious though on how this solution differs from the one
> suggested
> by Romain Guy. Anyone have any thoughts on this?

You asked for "heterogeneous rows". Your solution does not seem to
involve heterogeneous rows, unless I am missing something.

What Romain suggested was:

-- Override getViewTypeCount() to return the number of distinct types
of rows (e.g., 2)

-- Override getItemViewType() to return a value from 0 to
getViewTypeCount()-1, indicating which type of row to use for a given
position

-- In your getView() (or newView(), if you are extending
CursorAdapter), inflate the appropriate row layout for the position's
type, or recycle the supplied convertView -- by overriding the two
methods in the previous bullets, you ensure that convertView will be
of the desired layout

-- In your getView() (or bindView(), if you are extending
CursorAdapter), bind your model data into the right widgets based on
the row type

See also:

http://stackoverflow.com/questions/5300962/getviewtypecount-and-getitemviewtype-methods-of-arrayadapter
http://stackoverflow.com/questions/1660417/android-efficientadapter-with-two-different-views
http://stackoverflow.com/questions/3144555/different-views-on-a-single-list-android

and probably another 50 or so answers on StackOverflow, where
getViewTypeCount() and getItemViewType() appear.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.6 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to