I found many tutorials and examples butWhy ListView cannot be used in a ScrollView?
Only answers is Using a ListView to make it not scroll is extremely expensive and goes against the whole purpose of ListView. resources.
I have following xml file.
.........
<ScrollView
android:id="@+id/sv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2">
<ListView
android:id="@+id/list"
android:layout_width="275dp"
android:layout_height="200dp">
</ListView>
</ScrollView>
.........
In this xml file, i have already use
wrap_content instead of 200dp height of listview
ListView lv = (ListView) findViewById(R.id.list);
lv.setAdapter(new EfficientAdapter(this));
but doesnot work.
What is the alternative scrolling list item for specific height and weight.
But I have try this:
<ListView
android:id="@+id/list"
android:layout_width="275dp"
android:layout_height="200dp">
</ListView>
or
<ScrollView android:layout_width="fill_parent" android:id="@+id/sv"
android:layout_height="wrap_content" android:layout_below="@+id/textView2">
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<ListView android:id="@+id/list" android:layout_width="275dp"
android:layout_height="240dp"></ListView>
</LinearLayout>
</ScrollView>
Without scollview but scrolling the listitem is ok but quite not smothly. I have try this but could not get more idea behind this.
Edited:
Is it right Listview have inbuild scrolling capabilities. So not necessary to define listview inside the scrollview. It means scrollview in not necessary?
ListViews are not supposed to get in ScrollView. Even if you hack, and i mean big hack, both views by extending them and got them to scroll , also be itemclickable etc etc , something will break eventually. Also do not add a ListView to a Scroll View.
It's because both views are scrollable. Have you already tried to search/google for it? There are thousand matches..
http://www.google.de/search?sourceid=chrome&ie=UTF-8&q=android+listview+in+scrollview
The ListView has built in capabilities to scroll. You don't need to define it again within a ScrollView
I have tested with below xml and it works. But still trying to handle the onTouchEvent function between the ScrollView and ListView. You can Click here to see the original solution.
EDIT: Yes android doc says don't use listview into scrollview because both have same vertically touch gesture. It will make trouble at the time of scrolling item. And also problem with their adapter size that why we are unable to see whole item.
Finally I got best solution and I want share it with all. Please don't use Listview into Scrollview instead of it use LinearLayout and bind your item using View Infaltor.
And in your java class-
The problem is not the ListView but the ScrollView
Those two views need to takes controll of vertical scrolling, if you have a scrollview and a listview in the same layout and the user scroll down, which one have to take the focus and so the scroll?
This is a common problem that has a common and easy solution (this solution comes from Romain Guy from Google Android team!): don't use a listview in a scrollview!
If you want an interesting video/talk you can watch it from Google I/O talks: The world of ListView I really suggest you to take a look :)