0

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.

3
  • listview scrolls by itself. No need to put that inside a scrollview. Post your cod of networks calls and how you display it in listview. Commented Mar 12, 2013 at 8:43
  • First of all, you should not put a listview in a scroll view, and like @Raghunandan said, i suspect your scrolling issues are because of how you are handling the network calls. Commented Mar 12, 2013 at 8:49
  • I am not having any network calls in the ListView code, I am calling all network stuff before I add the adapter. I am calling Flurry events though. But Flurry events are async I think. Should not impact. Commented Mar 12, 2013 at 8:50

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Very precise answer @npace. I encourage you to participate more on stackoverflow.
Thanks. I'm new both to stackoverflow and to android development, so I only try to post when I actually know a good answer.
2

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

Comments

2

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); 

1 Comment

Answer from altaf did the trick. I was missing the "addFooterView". And thanks for your answer. Very concise and to the point.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.