Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faster loading ListView, faster than the Viewholder method

When inflating views for a listView, is it better to have all textViews without android:text in the .xml file and how much does that affects the speed? What about ViewStubs, would that be even faster?

When inflating a LinearLayout with 8 textViews without android:text and with android:text="@string/abc", does that change anything ? note that i am reusing views, so maybe only 10 get inflated and then reused i don't know.

I am developing on a ZTE Blade, so that'a single 600Mhz CPU and not a quad core ...

like image 575
max4ever Avatar asked Jul 26 '12 14:07

max4ever


People also ask

Which is better ListView or RecyclerView?

Simple answer: You should use RecyclerView in a situation where you want to show a lot of items, and the number of them is dynamic. ListView should only be used when the number of items is always the same and is limited to the screen size.

Why is RecyclerView used select one efficient all of them memory management faster?

It's more efficient by default, the layout is separated and we have more possibilities over the data set inside the adapter. The ViewHolder pattern allows us to make our list scrolling act smoothly.


2 Answers

You can try this, not sure if it will speed up, but give it a shot.

Inflate the layout in a background thread.

View getView(int position, View convertView, ...) {
    View v;
    if (convertView == null) {
        Start a background thread to inflate your linearLayout. 
        Pass item data and view 'v' to it.

        v = inflate a simple dummy textview;
        return v;
    }
    set normal stuff to convertview here.
    return convertView ;
 }

In the background thread,

  • Inflate your Linearlayout into 'v'
  • Set all the data.
  • Then invalidate the view v.

    v.postInvalidate();
    
like image 100
Ronnie Avatar answered Oct 21 '22 09:10

Ronnie


This is quite helpful when speeding up list views, especially the View Holder bit: http://developer.android.com/training/improving-layouts/smooth-scrolling.html

I've got a ZTE Blade too, they're slow, but apps that run well on it run amazing on 'normal' phones :)

like image 45
Todd Davies Avatar answered Oct 21 '22 09:10

Todd Davies