How to make ListView super fast

This might be the most asked question. How a listview can be made faster/smoother is really all about optimizations of the code.



You should probably always use a Holder class not to findViewById in every getView call. According to a google IO thingy, this would slightly increase the performance of your ListView.

Of course, do not forget to use the logic: if(convertView == null) then (convertView = new InflatedView). Then intialise everything in convertView... bla bla bla.

However, today I got a +1 on one of my answers on stackoverflow. I gave away a small hack.
@Override
public long getItemViewType(int position) {
     return position;
}
@Override
public long getViewTypeCount(int position) {
     return getCount();
}
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
    if (convertView == null) {
        //inflate your convertView and set everything
    }
    //do not do anything just return the convertView
    return convertView;
}

I found out that I had a small typo: I fixed that. Anyway, I would like to give this away and it would really be nice to tell me if this does not work with you.
The hack is simple: I give each view its own view type, and, therefore, I force the ListView to do the whole caching on its own.

3 comments:

  1. this is shushCrappy code. :p

    ReplyDelete
    Replies
    1. I think I know who is this shushpicious body that commented.

      Delete
  2. The best way to protect your expensive smartphone is by using a case.
    It not only protects your phone from damage due to accidental drop, but also imparts beauty to your phone.
    Here are some of the best and exclusive cases for you.
    You can check them out and select one for your phone Galaxy S8 TPU Cases

    ReplyDelete