Search code examples
androidbaseadaptergetviewconvertview

should I always use convertView as my main ViewElement in Base adapter?


the variable convertView in getView of BaseAdapter . What is it for? when creating items should I always use convertView? What is the problem if I don't use it?


Solution

  • What is it for? 
    

    it an instance of the View if you inflate, the first time its value is null. E.g.

     if (convertView == null) {
          convertView = inflate...
     }
    

    when creating items should I always use convertView?

    yes, but try to implement the ViewHolder pattern around it. It will speed up the scroll's performance.

    What is the problem if I don't use it?

    it depends on the the number of items you have in your ListView. We can go from laggy ux to crashes.