title: What is the benefit of ViewHolder pattern in android?
body: <p>When you are developing an Android program; and you want to have a <strong>ArrayAdapter</strong> you can Simply have a Class (most of times with <strong>ViewHolder</strong> suffix) or directly inflate your <strong>convertView</strong> and find your view by id.<br>
  <strong>So What is the benefit of using ViewHolder?</strong><br>
  The example of both here :</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
          convertView = ((Activity)getContext()).getLayoutInflater().inflate(R.layout.row_phrase, null);
      }
      ((TextView) convertView.findViewById(R.id.txtPhrase)).setText("Phrase 01");
  }
  </code></pre>
  
  <p>Or create an inner class in the ArrayAdapter as following:</p>
  
  <pre><code>static class ViewHolder {   
      ImageView leftIcon;   
      TextView upperLabel;  
      TextView lowerLabel;  
  }
  </code></pre>
  
  <p>and finally in the getView :</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = null;
      if (view == null) {
          view = LayoutInflater.from(context).inflate(R.layout.row_layout,
                      null, false);
          holder = new ViewHolder();
          holder.leftIcon = (ImageView) view.findViewById(R.id.leftIcon);
      }
  }
  </code></pre>