1

Here i am using scrollview in my linearlayout.But i want to include another listview inside my scrollview linearlayout.

Scrollview supports ony one child.I know that inside scrollview listview is not working.But is there any other option to use listview.I want to scroll all the content.

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView
        android:id="@+id/widget54"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        >
        <LinearLayout
            android:layout_width="310px"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <Button
                android:id="@+id/button1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Button 1"
                />
            <Button
                android:id="@+id/button2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Button 2"
                />
            <Button
                android:id="@+id/button3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Button 3"
                />
            <EditText
                android:id="@+id/txt"
                android:layout_width="fill_parent"
                android:layout_height="300px"
                />
            <Button
                android:id="@+id/button4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Button 4"
                />

        </LinearLayout>
    </ScrollView>
rajeshlawrance
  • 549
  • 2
  • 6
  • 25
  • You can see this : http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing – user3682351 Jun 02 '16 at 03:21

2 Answers2

1

ListView inside ScrollView is pretty sure not working.

The only method i can think of, is you have only one listview in the interface, and, create a custom adapter for it:

public class HeaderAdapter{
    private Adapter mAdapter; // this adapter is the adapter that you will normally have, for your listview

    getViewTypeCount(){
        return mAdapter.getViewTypeCount() + 1;
    }

    getView(int pos, View convertView){
        // Handle only the first position, othervise, let mAdapter return
        if (pos!=0) return mAdapter.getView(pos-1, convertView);

        // 
        View v = LayoutInflater.inflate(R.layout.other_linear_layout);
        // Bind the v if necessary

        return v;
    }
}

Above is just an example, idea is you treat the rest of the content (linearlayouts, buttons, edittext etc) as the "Header" row of the adapter.

xandy
  • 27,357
  • 8
  • 59
  • 64
0

If you have only one ListView int the ScrollView, you can add an attribute to the ScrollView in the layout XML: android:fillViewport="true".

This will expand all content of the ListView.

Else if you have more than one ListView or GridView in the ScrollView, you need to create a customListView.

Extends ListView and @Override onMeasure:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
}
Evgeniy Chekan
  • 2,615
  • 1
  • 15
  • 23
Philo_z
  • 31
  • 1