标签:pos tin get blog inflate 实例 adapter ati 使用
//减少对象的创建 if (convertView == null) { //实例化一个布局文件 convertView = LayoutInflater.from(context).inflate(R.layout.my_simple_adapter, null); }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; //减少对象的创建 if (convertView == null) { //实例化一个布局文件 convertView = LayoutInflater.from(context).inflate(R.layout.my_simple_adapter, null); viewHolder = new ViewHolder(); viewHolder.img = (ImageView) convertView.findViewById(R.id.img); viewHolder.title = (TextView) convertView.findViewById(R.id.text); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } System.out.println(convertView); viewHolder.title.setText(titles[position]); viewHolder.img.setImageResource(icons[position]); return convertView; } //用于保存第一次查找的组件, 避免下次重复查找 static class ViewHolder { //不封装 效率更高 ImageView img; TextView title; } }
标签:pos tin get blog inflate 实例 adapter ati 使用
原文地址:http://www.cnblogs.com/SandyLam/p/6033453.html