-
适配器的数据更新方法notifyDataSetChanged()只有在定义Adapter类时可以调用;
-
使用ViewHolder优化:
(1)创建Holder:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
class Holder{
ImageView imagerView;
TextView textView;
.........
} ( 2 ) public View getView( int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub Holder holder = null ;
if (convertView== null ) {
convertView=LayoutInflater.from(context).inflate(resource, null );
holder= new Holder();
holder.imageView=(ImageView) convertView.findViewById(R.id.imageView);
holder.textView=(TextView) convertView.findViewById(R.id.textView);
convertView.setTag(holder);
} else {
holder=(Holder) convertView.getTag();
}
holder.imageView.setImageResource(image);
holder.textView.setText(text)
} |
(3)View.setTag(Object)和View.getTag():
为View设置附加数据,可以在需要的时候拿来用,在adapter使用是避免了控件的重复实例话,算是一种简单的优化;
本文转自wauoen51CTO博客,原文链接:http://blog.51cto.com/7183397/1604340 ,如需转载请自行联系原作者