Reputation: 9584
Using scrolling listview seems really buggy. I have a listview, adapter on which I prepare all the data (with all the network calls), and then populate the listview adapter.
The scrolling is just not smooth, and most of the time does not work if I implemented ListView within a ScrollView
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/rideList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/customersTitle"
android:background="@drawable/roundcornersgreyback"
android:scrollbarSize="3dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:visibility="visible" />
</ScrollView>
When I scroll without the ScrollView, just use the attributes of the ListView itself, the list scrolls, but there is a part that is lost on the bottom of my layout. The footer is hidden.
<ListView
android:id="@+id/rideList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/customersTitle"
android:background="@drawable/roundcornersgreyback"
android:scrollbarSize="3dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:visibility="visible" />
If I get the ScrollView to the root of the layout, the list view fails to scroll at all.
What am I doing wrong ? Is it that crazy to need to scroll the list and the view ?
Edit : The code is as per viewHolder layout.
Upvotes: 0
Views: 4314
Reputation: 133570
The world of listview by google developers. Have a look at the link. Explains using viewholder and why it increases performance. Use a ViewHolder in you custom list adapter. Recycling views will help scrolling smooth. Thoese views that are visible in the screen cannot be recycled.
You are calling findViewById() everytime. So as the list increases the performance decreases. So recycling views is the way to increase your listview performance.
This link http://www.vogella.com/articles/AndroidListView/article.html has tutorials and helps you understand ViewHolder under the heading VIEWHOLDER PATTERN.
static class ViewHolder {
TextView text;
}
ViewHolder holder = new ViewHolder();
if(convertView==null)
{
holder.text = (TextView) convertView.findViewById(R.id.listitem_text);
convertView.setTag(viewHolder);
}
holder = (ViewHolder) rowView.getTag();
holder.text.setText("hello);
Upvotes: 2
Reputation: 4425
Listview footer use as your footer layout
View footerView = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
list.addFooterView(footerView);
http://developer.android.com/reference/android/widget/ListView.html
Upvotes: 2
Reputation: 4258
From what I understand, there are at least two problems making your implementation laggy:
First and foremost, you are using a ListView within a ScrollView, which is not a great idea. From the API documentation on ScrollView:
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
Second, if you really want your ListView to scroll smoothly, you should use an adapter that implements the ViewHolder pattern to recycle views instead of creating a new one for each list element. There are plenty of good examples out there, just search something like "ListView ViewHolder" and you will get some great tutorials.
Upvotes: 3