Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You probably should just manually add your items to <code>LinearLayout</code>:</p> <pre><code>LinearLayout layout = ... // Your linear layout. ListAdapter adapter = ... // Your adapter. final int adapterCount = adapter.getCount(); for (int i = 0; i &lt; adapterCount; i++) { View item = adapter.getView(i, null, null); layout.addView(item); } </code></pre> <p><strong>EDIT</strong>: I rejected this approach when I needed to display about 200 non-trivial list items, it is very slow - Nexus 4 needed about 2 seconds to display my "list", that was unacceptable. So I turned to Flo's approach with headers. It works much faster because list views are created on demand when user scrolls, not at the time the view is created.</p> <p><strong>Resume:</strong> The manual addition of views to layout is easier to code (thus potentially less moving parts and bugs), but suffers from performance problems, so if you have like 50 views or more, I advise to use the header approach.</p> <p>Example. Basically the activity (or fragment) layout transforms to something like this (no ScrollView needed anymore):</p> <pre><code>&lt;ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my_top_layout" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; </code></pre> <p>Then in <code>onCreateView()</code> (I'll use an example with a fragment) you need to add a header view and then set an adapter (I assume the header resource ID is <code>header_layout</code>):</p> <pre><code>ListView listView = (ListView) inflater.inflate(R.layout.my_top_layout, container, false); View header = inflater.inflate(R.layout.header_layout, null); // Initialize your header here. listView.addHeaderView(header, null, false); BaseAdapter adapter = // ... Initialize your adapter. listView.setAdapter(adapter); // Just as a bonus - if you want to do something with your list items: view.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // You can just use listView instead of parent casted to ListView. if (position &gt;= ((ListView) parent).getHeaderViewsCount()) { // Note the usage of getItemAtPosition() instead of adapter's getItem() because // the latter does not take into account the header (which has position 0). Object obj = parent.getItemAtPosition(position); // Do something with your object. } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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