总结listview: 1、创建-->高度match 2、创建-->行布局 3、找到listview控件 4、初始化数据 5、创建适配器对象 baseAdapter getview :决定了显示的样式以及内容 查找当前布局对象里面的控件 行布局对象.findviewById() getCount :决定listview的显示行数 6、设置适配器
listview优化:
1、用完全消失的布局对象去替代即将出现的那个布局对象 复用行布局对象 convertView
View inflate = null;
// convertView用来保存完全消失的那个布局对象
if(convertView==null){
// 把布局xml文件转换成布局对象
// 得到布局转换器
LayoutInflater layoutInflater = getLayoutInflater();
// 通过布局转换器把xml文件转换成布局对象
inflate = layoutInflater.inflate(R.layout.ssa, null);
}else{
//用完全消失的布局对象去替代即将出现的那个布局对象
inflate = convertView;
}
2、减少控件的查找次数 //创建一个类,类里面的属性就是我们所需的控件 //声明一个ViewHolder对象 ViewHolder holder = null;
if (convertView == null)
{
holder = new ViewHolder();
// 把布局xml文件转换成布局对象
// 得到布局转换器
LayoutInflater layoutInflater = getLayoutInflater();
// 通过布局转换器把xml文件转换成布局对象
inflate = layoutInflater.inflate(R.layout.ssa, null);
//找到控件对象,然后保存到holder对象里面去
holder.textView1 = (TextView) inflate.findViewById(R.id.textView1);
holder.textView2 = (TextView) inflate.findViewById(R.id.textView2);
//把holder放到inflate包里面去
inflate.setTag(holder);
}
else
{
// 用完全消失的布局对象去替代即将出现的那个布局对象
inflate = convertView;
//从inflate对象的包里面得到holder
holder = (ViewHolder) inflate.getTag();
}
注·:文章来自51CTO博客作者Samuel_humg
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有