• ListView的性能提升


    1 public class Fruite{
    2     private String name;
    3     private int imageId;
    4     public Fruit(String name,int imageId){
    5         this.name = name;
    6         this.imageId = imageId;
    7     }
    8 }
     1 public class FruitAdapter extends ArrayAdapter<Fruit>{
     2     private int resourceId;
     3     public FruitAdapter(Context context,int textViewresourceId,
     4                                         List<Fruit> objects){
     5                 super(context,textViewResourceId,objects);
     6                 resourceId = textViewResourceId;
     7     }
     8     
     9 public View getView(int position, View convertView, ViewGroup parent) {
    10     Fruit fruit = getItem(position);
    11     View view;
    12     ViewHolder viewHolder;
    13     if (convertView == null) {
    14     view = LayoutInflater.from(getContext()).inflate(resourceId,     null);
    15     viewHolder = new ViewHolder();
    16     viewHolder.fruitImage = (ImageView) view.findViewById
    17 (R.id.fruit_image);
    18     viewHolder.fruitName = (TextView) view.findViewById
    19 (R.id.fruit_name);
    20     view.setTag(viewHolder); // 将ViewHolder存储在View中
    21 } else {
    22     view = convertView;
    23     viewHolder = (ViewHolder) view.getTag(); // 重新获取ViewHolder
    24 }
    25             viewHolder.fruitImage.setImageResource(fruit.getImageId());
    26     viewHolder.fruitName.setText(fruit.getName());
    27     return view;     
    28 }                   
    1 class ViewHolder {
    2 ImageView fruitImage;
    3 TextView fruitName;
    4 }
  • 相关阅读:
    centos安装pip
    centos修改国内镜像源
    centos配置snmp服务
    django使用ModelForm上传文件
    Vue slot
    umi3.2+ targets ie不生效的问题
    mongo环境快速搭建工具 mlaunch
    mac上常用软件
    磁盘性能测试工具 iozone
    磁盘性能测试工具 bonnie++
  • 原文地址:https://www.cnblogs.com/plmmlp09/p/4225462.html
Copyright © 2020-2023  润新知