首页 > 其他 > 详细

ListView优化

时间:2015-10-28 01:26:20      阅读:240      评论:0      收藏:0      [点我收藏+]

在获得布局填充view的时候我们一般用到的是View.inflate()方法,我们每滑动一次getview就要执行一次同样,也要填充一次布局,

listview只能显示屏幕那么多的内容,而不用的不会马上销毁而是放到缓存里,这样我们就可以利用这点来进行优化,当有缓存的时候我

们就要用到缓存,不用重新调用View.inflate()

代码实现

// 返回视图,这个方法很主要
    public View getView(int position, View arg, ViewGroup arg2) {
        View view = null;
        
    //判断是否有缓存,如果没有填充布局,有的话利用缓存。不管是缓存还是新获取的都要重新设置内容
    if(arg==null){ view = View.inflate(context, R.layout.lisviewt_item1, null); }else{ view = arg; } FriendBean fb = data.get(position); ImageView img = (ImageView) view.findViewById(R.id.iv); TextView name = (TextView) view.findViewById(R.id.tv_1); TextView gexing = (TextView) view.findViewById(R.id.tv_2); img.setImageResource(fb.getImgID()); name.setText(fb.getName()); gexing.setText(fb.getGexing()); return view; }

 

ListView优化

原文:http://www.cnblogs.com/84126858jmz/p/4916036.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!