What is the purpose of `convertView` in ListView adapter?

前端 未结 4 1976
逝去的感伤
逝去的感伤 2020-12-08 07:58

In android, I usually use MyAdapter extends ArrayAdapter to create view for the ListView, and as a result, I have to override the function

4条回答
  •  自闭症患者
    2020-12-08 08:14

    convertView is used to reuse old view.

    Please understand Adapter functionality in android. Adapter enables you to reuse some view with new data.

    So if a list is of 15 items, but window can show only 5 items, then at first convertView would be null, and we need to create new views for these five items, but when you scroll down, you have two options, either create 6-10 views, or re-use old views and load new data into these views. Adapter and convertView enables you to do the later method.

提交回复
热议问题