给ListView通过自定义适配器显示数据,需要哪些步骤 - 爱问答

(爱问答)

给ListView通过自定义适配器显示数据,需要哪些步骤

首先:需要创建一个ListView控件,自定义适配器是为了实现自定义ListView的ListView_Item,所以我们应该在创建一个Item

然后书写自定义适配器,自定义适配器的时候需要继承BaseAdapter,然后实现它的未实现的4个方法,然后在实现自定义适配器的构造方法,其构造方法的参数为山下文对象,数据源,必须实现的4个方法主要是对数据源进行过操作,

然后考虑优化方面,我们使用了ViewHolder Pattern,用它的优点(我们来看一下来自国外网友的看法):

  Now let’s see how it works with the ViewHolder pattern.

       1.The first time it was loaded, convertView is null. We’ll have to inflate our list item layout, instantiate the ViewHolder, find the TextView via

       findViewById·() and assign it to the ViewHolder, and set the ViewHolder as tag of convertView.

      2.The second time it was loaded, convertView is not null, good! We don’t have to inflate it again. And here’s the sweet thing, we won’t have to call

     findViewById() since we can now access the TextView via its ViewHolder.

      3.The following time it was loaded, convertView is definitely not null. The findViewById() is never called again, and that makes our smooth ListView scrolling.


下一篇:云存储架构包含哪些内容

上一篇:c语言代码,求字符串"ABCXYZ"的长度是多少个字节

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?