总结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