title: How to speed up listview control?
body: <p>I use a customize listview control to display image and other informations. The listview control is little slow when I scroll it to display more content.</p>
  
  <p>After I test the control, I find the function <code>SetControlsValue</code> to do many works. I must to do some work to improve it.</p>
  
  <p>The <strong>Method 1</strong> is my way, is it correct? is there other the better way?</p>
  
  <p><strong>Method 1</strong></p>
  
  <pre><code> private void SetControlsValue(ViewHolder holder,int position){
  
          holder.mCheckBox.setChecked(mListCheckedStatus.get(position));
  
          new BMPOperation().execute(position,holder);
  
          new LongOperation().execute(position,holder);
      }
  
      private class BMPOperation extends AsyncTask&lt;Object, Void, Bitmap&gt; {
          private ViewHolder myHolder;
  
          @Override
          protected Bitmap doInBackground(Object... params) {
              int position=(Integer)params[0];
              myHolder=(ViewHolder)params[1];
  
              Bitmap mBitmap=mListVideo.get(position).GetBitmapOfVideo();
  
              return mBitmap;
  
          }
          @Override
          protected void onPostExecute(Bitmap mBitmap) {
              try {
                  if (mBitmap != null) {
                      myHolder.imageViewthumb.setImageBitmap(mBitmap);
                  }
              }catch (Exception e){
                  Utility.LogError(e.getMessage());
              }
          }
  
          @Override
          protected void onPreExecute() {}
  
          @Override
          protected void onProgressUpdate(Void... values) {}
      }
  
  
  
      private class LongOperation extends AsyncTask&lt;Object, Void, String&gt; {
          private ViewHolder myHolder;
  
          @Override
          protected String doInBackground(Object... params) {
              int position=(Integer)params[0];
              myHolder=(ViewHolder)params[1];
              String s=mListVideo.get(position).fileName
                      +"\n"+mContext.getResources().getString(R.string.TitleResolution)+ mListVideo.get(position).GetResolution()
                      +"\n"+mContext.getResources().getString(R.string.TitleSize)+mListVideo.get(position).GetSize()
                      +"\n"+mContext.getResources().getString(R.string.TitleDuration)+mListVideo.get(position).GetDuration();
  
              return s;
          }
  
          @Override
          protected void onPostExecute(String result) {
              myHolder.tvInfo.setText(result);
          }
  
          @Override
          protected void onPreExecute() {}
  
          @Override
          protected void onProgressUpdate(Void... values) {}
      }
  </code></pre>
  
  <p><strong>The Function SetControlsValue</strong></p>
  
  <pre><code>private void SetControlsValue(ViewHolder holder,int position){
          holder.mCheckBox.setChecked(mListCheckedStatus.get(position));
  
          Bitmap mBitmap=mListVideo.get(position).GetBitmapOfVideo();
  
          try {
              if (mBitmap != null) {
                  holder.imageViewthumb.setImageBitmap(mBitmap);
              }
          }catch (Exception e){
              Utility.LogError(e.getMessage());
          }
  
          String s=mListVideo.get(position).fileName
                  +"\n"+mContext.getResources().getString(R.string.TitleResolution)+ mListVideo.get(position).GetResolution()
                  +"\n"+mContext.getResources().getString(R.string.TitleSize)+mListVideo.get(position).GetSize()
                  +"\n"+mContext.getResources().getString(R.string.TitleDuration)+mListVideo.get(position).GetDuration();
          holder.tvInfo.setText(s);
      }
  </code></pre>
  
  <p><strong>ListVideoAdapter.java</strong></p>
  
  <pre><code>public class ListVideoAdapter  extends BaseAdapter {
  
      private Context mContext;
      private LayoutInflater mInflater;
  
      private List&lt;Video&gt; mListVideo;
  
      private List&lt;Boolean&gt; mListCheckedStatus;
  
      public ListVideoAdapter (Context context){
          mContext=context;
          mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          mListVideo= VideoHelper.ListVideo(mContext);
  
      }
  
  
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return mListVideo.size();
      }
  
      @Override
      public Object getItem(int arg0) {
          // TODO Auto-generated method stub
          return arg0;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder;
          if (convertView == null) {
              holder = new ViewHolder();
              convertView = mInflater.inflate(R.layout.layout_adapter_video, null);
              IniControls(holder,convertView);
              convertView.setTag(holder);
  
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          SetControlsPosition(holder,position);
          SetControlsValue(holder,position);
          SetControlsEvent(holder);
  
          return convertView;
      }
  
  
      private void IniControls(ViewHolder holder,View convertView){
          holder.mCheckBox=(CheckBox) convertView.findViewById(R.id.chSelect);
          holder.imageViewthumb=(ImageView)convertView.findViewById(R.id.imageViewVideo);
  
          holder.tvInfo = (TextView) convertView.findViewById(R.id.tvInfo);
  
  
          holder.imageViewTrim=(ImageView)convertView.findViewById(R.id.imageViewTrim);
          holder.imageViewShare=(ImageView)convertView.findViewById(R.id.imageViewShare);
          holder.imageViewInfo=(ImageView)convertView.findViewById(R.id.imageViewInfo);
          holder.imageViewDelete=(ImageView)convertView.findViewById(R.id.imageViewDelete);
      }
  
  
      private void SetControlsPosition(ViewHolder holder,int position){
          holder.id=position;
          holder.mCheckBox.setId(position);
          holder.imageViewthumb.setId(position);
  
          holder.tvInfo.setId(position);
  
          holder.imageViewTrim.setId(position);
          holder.imageViewShare.setId(position);
          holder.imageViewInfo.setId(position);
          holder.imageViewDelete.setId(position);
      }
  
  
      private void SetControlsValue(ViewHolder holder,int position){
          holder.mCheckBox.setChecked(mListCheckedStatus.get(position));
  
          Bitmap mBitmap=mListVideo.get(position).GetBitmapOfVideo();
  
          try {
              if (mBitmap != null) {
                  holder.imageViewthumb.setImageBitmap(mBitmap);
              }
          }catch (Exception e){
              Utility.LogError(e.getMessage());
          }
  
          String s=mListVideo.get(position).fileName
                  +"\n"+mContext.getResources().getString(R.string.TitleResolution)+ mListVideo.get(position).GetResolution()
                  +"\n"+mContext.getResources().getString(R.string.TitleSize)+mListVideo.get(position).GetSize()
                  +"\n"+mContext.getResources().getString(R.string.TitleDuration)+mListVideo.get(position).GetDuration();
          holder.tvInfo.setText(s);
      }
  
  
      private void SetControlsEvent(final ViewHolder holder) {
  
  
      }
  
  }
  
  
  
  class ViewHolder {
      int id;
      CheckBox mCheckBox;
      ImageView imageViewthumb;
  
      TextView tvInfo;
  
      ImageView imageViewTrim;
      ImageView imageViewShare;
      ImageView imageViewInfo;
      ImageView imageViewDelete;
  
  }
  </code></pre>
  
  <p><strong>Added</strong></p>
  
  <p>I have read the sample code of UniversalImageLoader.</p>
  
  <p>I don't think UniversalImageLoader control fit my requirement.</p>
  
  <p>ImageLoader need to pass URL par </p>
  
  <pre><code>ImageLoader.getInstance().displayImage(IMAGE_URLS[position], imageView, options);
  </code></pre>
  
  <p>but in my app, there are other two codes which spend much time.</p>
  
  <ol>
  <li><p><code>Bitmap mBitmap=mListVideo.get(position).GetBitmapOfVideo();</code></p></li>
  <li><p><code>String s=mListVideo.get(position).fileName                            +"\n"+mContext.getResources().getString(R.string.TitleResolution)+ mListVideo.get(position).GetResolution()                            +"\n"+mContext.getResources().getString(R.string.TitleSize)+mListVideo.get(position).GetSize()                            +"\n"+mContext.getResources().getString(R.string.TitleDuration)+mListVideo.get(position).GetDuration();</code></p></li>
  </ol>
  
  <p>so I think I need the other better way to improve code.</p>
  
  <p><strong>BTW</strong>, in my function <code>Bitmap mBitmap=mListVideo.get(position).GetBitmapOfVideo()</code> not only get the thumbnail of a video, but also I need merger a Play icon to the thumbnail, so I don't think I can use <code>ImageLoader.getInstance().displayImage("file:///mnt/sdcard/myvideo.mp4", imageView)</code>.</p>