Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a ListAdapter to fill a LinearLayout inside a ScrollView layout
    text
    copied!<p>I'm facing a very common problem: I layed out an activity and now it turns out it should display a few items within this <code>ScrollView</code>. The normal way to do that would be to use the existing <code>ListAdapter</code>, connect it to a <code>ListView</code> and <em>BOOM</em> I'd have my list of items.</p> <p><strong>BUT</strong> You should not place a nested <code>ListView</code> in a <code>ScrollView</code> as it screws up the scrolling - even Android Lint complains about it.</p> <p>So here's my question:</p> <p>How do I connect a <code>ListAdapter</code> to a <code>LinearLayout</code> or something similar?</p> <p>I know this solution won't scale for a lot of items but my lists is very short (&lt; 10 items) so reusage of views is not really needed. Performance wise I can live with placing all views directly into the <code>LinearLayout</code>.</p> <p>One solution I came up with would be to place my existing activity layout in the headerView section of the <code>ListView</code>. But this feels like abusing this mechanism so I'm looking for a cleaner solution.</p> <p>Ideas?</p> <p><strong>UPDATE:</strong> In order to inspire the right direction I add a sample layout to show my problem:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/news_detail_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:visibility="visible"&gt; &lt;ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFF" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="@dimen/news_detail_layout_side_padding" android:paddingRight="@dimen/news_detail_layout_side_padding" android:paddingTop="@dimen/news_detail_layout_vertical_padding" android:paddingBottom="@dimen/news_detail_layout_vertical_padding" &gt; &lt;TextView android:id="@+id/news_detail_date" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal" android:text="LALALA" android:textSize="@dimen/news_detail_date_height" android:textColor="@color/font_black" /&gt; &lt;Gallery android:id="@+id/news_detail_image" android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingTop="5dip" android:paddingBottom="5dip" /&gt; &lt;TextView android:id="@+id/news_detail_headline" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal" android:text="Some awesome headline" android:textSize="@dimen/news_detail_headline_height" android:textColor="@color/font_black" android:paddingTop="@dimen/news_detail_headline_paddingTop" android:paddingBottom="@dimen/news_detail_headline_paddingBottom" /&gt; &lt;TextView android:id="@+id/news_detail_content" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Here comes a lot of text so the scrollview is really needed." android:textSize="@dimen/news_detail_content_height" android:textColor="@color/font_black" /&gt; &lt;!--- HERE I NEED THE LIST OF ITEMS PROVIDED BY THE EXISTING ADAPTER. They should be positioned at the end of the content, so making the scrollview smaller is not an option. ----&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>UPDATE 2</strong> I changed the headline to make it easier to understand (got a downvote, doh!).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload