ListView的优化
发布日期:2021-08-22 21:41:54 浏览次数:0 分类:技术文章

hot3.png

1. 复用 convertview  减少 getview 方法对 Inflater 的操作

2.使用static的view对象的应用 减少内存中申请的局部变量的个数(或者使用viewHolder)

3.图片数据使用异步加载与缓存机制

public class AppListAdapter extends BaseAdapter {		private Context context ;	private List<AppInfo> appInfos ;		private static ImageView iv ;	private static TextView tv;	        public AppListAdapter(Context context, List<AppInfo> appInfos){		this.context=context;		this.appInfos=appInfos;	}		public void setAppInfos(List<AppInfo> appInfos) {		this.appInfos = appInfos;	}	@Override	public int getCount() {		return appInfos.size();	}	@Override	public Object getItem(int position) {		// TODO Auto-generated method stub		return appInfos.get(position);	}	@Override	public long getItemId(int position) {		return position;	}	@Override	public View getView(int position, View convertView, ViewGroup parent) {		View view;		if(convertView==null){			view = View.inflate(context, R.layout.app_item, null);		}else{			view = convertView;		                }		AppInfo appInfo = appInfos.get(position);		iv = (ImageView)view.findViewById(R.id.iv_app_icon);		iv.setImageDrawable(appInfo.getIcon());		tv = (TextView)view.findViewById(R.id.tv_app_name);		tv.setText(appInfo.getAppName());		return view;	}}


转载于:https://my.oschina.net/AlexZhuang/blog/53324

上一篇:Android Timer
下一篇:nginx 部署(无图无说明)