Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two ListViews & ScrollView

I'm so close here and I've tried many things but cannot get it to work. I have two listviews here. What I want is for each listview to show its ENTIRE content. I don't want the listviews scrollable. I want the Scrollview that holds the listviews scrollable. The closest i've been able to get it (which is wrong) is so that each listview is scrollable. This means that each listview only shows like 1 1/2 cells. I would think this would be a dirt simple task but Android has some quirky things going on.

So again, each list view shows its entire content, even if that content height goes past the screen. Then all I have to do is scroll down to see the second list view which shows its entire content.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:orientation="vertical"
android:fillViewport="true">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:orientation="vertical"
android:fillViewport="true">
<LinearLayout 
android:layout_weight="10"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:text="@string/alerts_top_title"
android:gravity="center"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</TextView>
<ListView 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/cameraListAlerts" >
</ListView>
</LinearLayout>
<LinearLayout 
android:layout_weight="10"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:gravity="center"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:textColor="#000000"
android:text="@string/alerts_bottom_title">
</TextView>
<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="8dp">
</LinearLayout>
<Button
android:id="@+id/addRecipient"
android:layout_height="50dp"
android:layout_width="fill_parent"
android:layout_centerHorizontal="true"
android:text="@string/addRecipient"/>

<ListView 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/recipientListAlerts" >
</ListView>
</LinearLayout>
</LinearLayout>
</ScrollView>
like image 318
spentak Avatar asked Jun 26 '11 04:06

spentak


1 Answers

You're going to spend far more time and energy trying to get this to work if it ever does. ListViews exist to handle long lists that require too many resources to be drawn at one time. They recycle the row Views when you scroll through them to allow for a snappy load. You're trying to ditch that functionality, thereby making your use of the ListView essentially pointless.

Populating a LinearLayout programmatically is no big deal at all. Do you have an XML file for your rows? Inflate it for each new row as you run an extremely simple for loop through your Array or while loop through your Cursor, binding the data, and adding it to your LinearLayout.

Done. No scrolling issues... it's all handled by the ScrollView like it should be.

like image 108
Glendon Trullinger Avatar answered Oct 28 '22 10:10

Glendon Trullinger