关于android:Android-学习笔记androidlistview总结

4次阅读

共计 1085 个字符,预计需要花费 3 分钟才能阅读完成。

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

正文完
 0