Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly some points about your code:</p> <ul> <li><code>layout_weight</code> is only meaningful if an object has no size in a certain dimension, that is you set <code>layout_height</code> or <code>layout_width</code> to 0, so this has no effect on your code.</li> <li>Setting the height of a ListView to <code>wrap_content</code> is pretty meaningless, and even if it works it's bad practice. Use either 'fill_parent' or a definite height.</li> <li>The button is hidden because, as per the point above, the ListViews you have created have no predefined size so take up as much space as they can, pushing the button off the screen.</li> </ul> <p>So let's think about what you really have there - it's just a single list with a button at the bottom (yes you may have headers or multiple sources of data in there but we'll get onto that).</p> <p>The following layout will give you a ListView at the top and a Button at the bottom. The ListView will take up any space not being used by the Button. Notice how the Button is defined <strong>before</strong> the ListView in the layout - this causes Android to calculate how much height the button takes up before considering the ListView. It then gives the ListView the rest of the height available.</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;Button android:id="@+id/btscan" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="@string/btscan" /&gt; &lt;ListView android:id="@+id/all_devices" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@id/btscan" android:stackFromBottom="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>So that's the layout. Now lets consider the actual content of your list: you have a header, followed by a list of paired devices, followed by another header and then a list of new devices. </p> <p>You can create this using a single Adapter - Commonsware provides a very good implementation called <a href="https://github.com/commonsguy/cwac-merge">MergeAdapter</a> but you could code your own. MergeAdapter doesn't directly let you a view (e.g. for the headers) but thankfully Commonsware also provides the <a href="https://github.com/commonsguy/cwac-sacklist/tree/master/src/com/commonsware/cwac/sacklist">SackOfViewsAdapter</a> which allows you to add views to it, and then you can add the SackOfViewsAdapter to the MergeAdapter.</p> <p>Here is some pseudo-code which should accomplish what is outlined above.</p> <pre><code>// This is the adapter we will use for our list with ListView.setAdapter MergeAdapter listAdapter = new MergeAdapter(); // The first header - you'll need to inflate the actual View (myHeaderView1) from some resource // using LayoutInflater List&lt;View&gt; firstHeaderViews = new List&lt;View(); firstHeaderViews.add(myHeaderView1); SackOfViewsAdapter firstHeaderAdapter = new SackOfViewsAdapter(firstHeaderViews) // Second header List&lt;View&gt; secondHeaderViews = new List&lt;View(); secondHeaderViews.add(myHeaderView2); SackOfViewsAdapter secondHeaderAdapter = new SackOfViewsAdapter(secondHeaderViews); // Now to add everything to the MergeAdapter // First goes the first header listAdapter.addAdapter(firstHeaderAdapter); // Now your first list listAdapter.addAdapter(firstListAdapter); // Now your second header listAdapter.addAdapter(secondHeaderAdapter); // Now your second list listAdapter.addAdapter(secondListAdapter); // Now set the adapter to the list myList.setAdapter(listAdapter) </code></pre> <p>The layout produced should look something <a href="http://i.imgur.com/sdTR4.png">like this</a>. Note I extended the list to show how it behaves with a list longer than the screen; the button still remains visible. The red box marks the bounds of the screen.</p>
    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.
    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