适配器:
//缓存类
class ViewHolder{
ImageView img;
TextView name;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if(convertView==null){
convertView=LayoutInflater.from(context).inflate(R.layout.item_spinn,parent,false);
viewHolder=new ViewHolder();
viewHolder.img=(ImageView) convertView.findViewById(R.id.iv_img);
viewHolder.name=(TextView) convertView.findViewById(R.id.tv_name);
//将页面存到缓存类
convertView.setTag(viewHolder);
}
viewHolder=(ViewHolder) convertView.getTag();
Country country=list.get(position);
viewHolder.img.setImageResource(country.getImg());
viewHolder.name.setText(country.getName());
return convertView;
}