title: Android RecyclerView.Adapter onCreateViewHolder() working
body: <p>I am using RecyclerView.Adapter but I am little confused regarding working of its method <code>onCreateViewHolder</code>. </p>
  
  <pre><code>  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
      if(viewType==TYPE_ITEM) {
  
          View mView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.inflate_common_item, viewGroup, false);
          ViewHolder vh = new ViewHolder(mView);
          return vh;
  
      } else {
          View mView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.inflate_uncommon_item, viewGroup, false);
          ViewHolderFooter vh = new ViewHolderFooter(mView);
          return vh;
  
      }
  }
  </code></pre>
  
  <p>So incase I have 10 items in my list so for each item this method will be called and every time a new <code>ViewHolder</code> will be created of course it'll one time for each view but now my question is when we were using <code>ListView</code> and <code>BaseAdapter</code> with them we store <code>ViewHolder</code> in tag and use that. We don't create <code>ViewHolder</code> for each item. </p>
  
  <pre><code> @Override
      public View getView(int position, View convertView, ViewGroup parent) {
              MyViewHolder mViewHolder;
  
              if(convertView == null) {
                      convertView = inflater.inflate(R.layout.layout_list_item, null);
                      mViewHolder = new MyViewHolder();
                      convertView.setTag(mViewHolder);
              } else {
                      mViewHolder = (MyViewHolder) convertView.getTag();
              }
  
              mViewHolder.tvTitle = detail(convertView, R.id.tvTitle, myList.get(position).getTitle());
              mViewHolder.tvDesc  = detail(convertView, R.id.tvDesc,  myList.get(position).getDescription());
              mViewHolder.ivIcon  = detail(convertView, R.id.ivIcon,  myList.get(position).getImgResId());
  
              return convertView;
      }
  </code></pre>
  
  <p>So are we not creating extra viewholders object. Please help me understand the pros and cons.</p>
  
  <p>Thanks</p>