0

I have a scrollview with a linear layout in it. Within that linear layout there is a list view. The problem I am having is that my list view only has a certain amount of space and then becomes scrollable. I don't want this to happen. I want the entire list to be shown. Does anyone know how I might achieve this? I have tried using this link however my layout does not appear when I add the footer. ListView in ScrollView potential workaround This is my code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="true"
    android:orientation="vertical"
    android:background="@drawable/darkimg"
    android:weightSum="1">

    <LinearLayout
        android:id="@+id/numbersLL"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="@drawable/round_rectangle"
        android:layout_margin="4px"
        android:paddingLeft="6px"
        android:paddingTop="3px">

        <TextView
            android:id="@+id/numberPrint"
            android:layout_height="wrap_content"
            android:textSize="14px"
            android:textStyle="bold"
            android:textColor="@color/white"
            android:layout_width="fill_parent"
            android:text="@string/numberPrint">
        </TextView>

        <ListView
            android:id="@+id/numberListView"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"></ListView>
    </LinearLayout>

</LinearLayout>
</ScrollView>

This is my footer:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/formLL">

<TextView
    android:id="@+id/numberFormTextViewt"
    android:layout_gravity="center_vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="20px"
    android:text="Add a number:"
    android:textColor="@color/white" />

<Button
    android:id="@+id/numberFormButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_add"></Button>
</LinearLayout>

And this is the Java code to add the footer to the list:

        LayoutInflater factory = getLayoutInflater();
        LinearLayout numberFooter = (LinearLayout) factory.inflate(R.layout.number_form, null);
        // List of numbers
        numberListView = (ListView) this.findViewById(R.id.numberListView);
        numberListView.addFooterView(numberFooter);

What is going wrong here? The footer does not appear when the activity is displayed. One thing I should mention is the footer is used to add items to the list above it. I'm not sure if that makes a difference but when I am testing this the list adapter is empty. Even still should the footer show up anyway? Any help would be appreciated thanks.

Community
  • 1
  • 1
Hugs
  • 915
  • 4
  • 20
  • 47
  • This [LInk](http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/ ) has perfect example just take a look.... also checkout this Question...[amongst us](http://stackoverflow.com/questions/6121186/android-listview-with-header-and-footer-buttons) – Hanry Aug 09 '11 at 13:37
  • Thanks for the comment. I'm not sure this will help me though as I am attempting to have several ListViews with different footers. – Hugs Aug 09 '11 at 14:17
  • Wait I see the height of the List is 0dp so it might work. Not used to relative Layouts but I'll give it a go. – Hugs Aug 09 '11 at 14:18
  • Let me know so I can post it as answer... – Hanry Aug 09 '11 at 14:22
  • 1
    I am going to do this an entirely different way. From more research I've realised using a ListView in a scrollview is bad practice. – Hugs Aug 09 '11 at 15:29

2 Answers2

0

try this in your listview:

android:layout_height="fill_parent"
Luke
  • 11,426
  • 43
  • 60
  • 69
Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
  • I've already tried that it doesn't work. The list will continue to scroll. The workaround from the other post seems like the solution for me but my footer won't show up. – Hugs Aug 09 '11 at 13:27
0

List view under scroll view is not working(means List view is not scrollable).

So u can put empty Linear Layout instead of List view in ur xml file. In ur code, first u can get the list view size, based on this size value, for loop can rotated. In that for loop u can call the get view method of the adapter class(that class is not extending any class.) this will solve the list view problem.

naresh
  • 10,332
  • 25
  • 81
  • 124