-5

Here is my xml layout file in which i use scrollview as parent in which list view lost their scrolling property..please suggest me what to do.. why listview lost their property of scrolling by default

   <android.support.v4.widget.NestedScrollView   xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:fillViewport="true"
                android:layout_height="match_parent">     
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:layout_centerHorizontal="true"
                            android:layout_marginRight="10dp"
                            android:text="Edit Order"
                            android:layout_marginTop="5dp"
                            android:id="@+id/txtyourOrder"
                            android:textColor="@android:color/holo_green_dark" />      
                        <TextView
                            android:id="@+id/textView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Your Order"
                            android:layout_marginLeft="10dp"
                            android:textColor="@android:color/black"
                            android:textSize="20sp" />        
                    <View
                        android:id="@+id/view1"
                        android:layout_below="@id/txtyourOrder"
                        android:layout_width="match_parent"
                        android:layout_height="0.5dp"
                        android:layout_marginTop="10dp"
                        android:background="@android:color/darker_gray" /> 
                    <ListView
                        android:layout_below="@id/view1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:nestedScrollingEnabled="true"
                        android:layout_marginTop="10dp"
                        android:id="@+id/listview"
                        android:textColor="@android:color/darker_gray" />        
                    <TextView
                        android:layout_below="@id/listview"
                        android:id="@+id/txtAddItems"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:layout_marginTop="10dp"
                        android:text="Add Items"
                        android:textColor="@android:color/holo_green_dark" />

                 </android.support.v4.widget.NestedScrollView>

Please help me!

kunal
  • 124
  • 13

2 Answers2

1

As defined here..

You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView. I strongly recommend you to simplify your layout somehow. For example you can add views you want to be scrolled to the ListView as headers or footers.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Saurabh Vardani
  • 1,821
  • 2
  • 18
  • 33
1

If you want to use ListView just use Co-Ordinator layout as root and design your layout according to that.

You can also add header on ListView like this:

LayoutInflater inflater = getLayoutInflater();
ViewGroup headerView = (ViewGroup)inflater.inflate(R.layout.header, 
listview, false);
myListView.addHeaderView(headerView, null, false);
Harsh Mittal
  • 449
  • 3
  • 10