zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    搭建 springboot selenium 网页文件转图片环境
    洛谷P1352没有上司的舞会-题解
    错误集合
    洛谷P1434滑雪-题解
    洛谷P1278单词游戏-题解
    洛谷P1219八皇后-题解
    洛谷P1443马的遍历-题解
    洛谷P1135奇怪的电梯-题解
    经验集合
    洛谷P1019单词接龙-题解
  • 原文地址:https://www.cnblogs.com/plmmlp09/p/4225462.html
Copyright © 2011-2022 走看看