Listview注意事项

1.缓存

@Override

public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;

    if (convertView == null) {

        convertView = inflater.inflate(R.layout.type_item, null);

        holder = new ViewHolder();

        holder.imageView = (ImageView)convertView.findViewById(R.id.app_icon);

        holder.textView = (TextView)convertView.findViewById(R.id.app_name);

        convertView.setTag(holder);

    } else {

        holder = (ViewHolder)convertView.getTag();

    }

    holder.imageView.setImageResource(R.drawable.index_default_image);

    holder.textView.setText("");

    return convertView;

}

 

/**

 * ViewHolder

 */

static class ViewHolder {

 

    ImageView imageView;

    TextView  textView;

}

  2.Listview的layout属性不要为wrap_content,不然会重复计算高度宽度

你可能感兴趣的:(ListView)