title: How to use Spinner in Recyclerview?
body: <p>Which are the best practice to handle a Spinner in a <code>RecyclerView</code> Adapter?</p>
  
  <p><strong>This is my <code>RecyclerView</code> Adapter:</strong></p>
  
  <pre><code>public class CartAdapter extends BaseAdapter&lt;Object&gt; {
  
  public CartAdapter(AbstractBaseActivity activity) {
      super(activity);
  }
  
  public static final int TYPE_PRODOTTO = 1;
  public static final int TYPE_SCONTO = 2;
  
  @Override
  public int getItemViewType(int position) {
  
      if (items.get(position) instanceof Article)
          return TYPE_PRODOTTO;
      else
          return TYPE_SCONTO;
  }
  
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View rowView = LayoutInflater.from(parent.getContext()).inflate(viewType == TYPE_PRODOTTO ? R.layout.item_cart : R.layout.item_cart_sconto, parent, false);
      return new ViewHolder(rowView);
  }
  
  @Override
  public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
      final ViewHolder viewHolder = (ViewHolder) holder;
  
      final Object object = items.get(position);
  
      if (object instanceof Article) {
  
          viewHolder.getBinding().setVariable(BR.article, object);
          viewHolder.getBinding().executePendingBindings();
  
          assert viewHolder.quantitySpinner != null;
          assert viewHolder.cartoneQuantity != null;
          assert viewHolder.cartoneValue != null;
  
          CartSpinnerAdapter adapter = (CartSpinnerAdapter) viewHolder.quantitySpinner.getAdapter();
          adapter.clear();
          adapter.setCount(((Article) object).getQuantityAvailable());
          adapter.notifyDataSetChanged();
  
          viewHolder.quantitySpinner.setSelection(((Article) object).getQuantity() - 1); //In teoria qui la quantità non deve mai essere zero
  
          viewHolder.cartoneQuantity.setVisibility(position % 2 == 1 ? View.GONE : View.VISIBLE); //Controllo da togliere in futuro
          viewHolder.cartoneValue.setVisibility(position % 2 == 1 ? View.GONE : View.VISIBLE); //Controllo da togliere in futuro
      }
  
      final PopupMenu popup = new PopupMenu(getContext(), viewHolder.deleteMenu);
      MenuInflater inflater = popup.getMenuInflater();
      inflater.inflate(R.menu.delete_menu, popup.getMenu());
  
      viewHolder.deleteMenu.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              popup.show();
          }
      });
  
      popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
              if (item.getItemId() == R.id.action_delete) {
                  removeData(holder.getAdapterPosition());
                  ((CartActivity) activity).checkIfEmpty();
              }
  
              return true;
          }
      });
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder {
  
      @BindView(R.id.item)
      View item;
      @Nullable
      @BindView(R.id.cart_image)
      ImageView cartImage;
      @BindView(R.id.delete_menu)
      ImageView deleteMenu;
      @Nullable
      @BindView(R.id.product_cartone_quantity)
      TextView cartoneQuantity;
      @Nullable
      @BindView(R.id.product_cartone_value)
      TextView cartoneValue;
      @Nullable
      @BindView(R.id.quantity_spinner)
      AppCompatSpinner quantitySpinner;
  
      private ViewDataBinding binding;
  
      public ViewHolder(View itemView) {
          super(itemView);
          ButterKnife.bind(this, itemView);
          binding = DataBindingUtil.bind(itemView);
          if (quantitySpinner != null)
              quantitySpinner.setAdapter(new CartSpinnerAdapter(itemView.getContext(), R.layout.support_simple_spinner_dropdown_item));
      }
  
      public ViewDataBinding getBinding() {
          return binding;
      }
  }
  }
  </code></pre>
  
  <p><strong>and this is my <code>Spinner</code> Adapter:</strong></p>
  
  <pre><code>public class CartSpinnerAdapter extends ArrayAdapter&lt;String&gt; {
  
  LayoutInflater inflater;
  
  int count;
  
  public CartSpinnerAdapter(Context context, int resource) {
      super(context, resource);
  
      inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  
  public CartSpinnerAdapter(Context context, int resource, int count) {
      super(context, resource);
  
      this.count = count;
      inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  
  public void setCount(int count) {
      this.count = count;
  }
  
  @Override
  public View getDropDownView(int position, View convertView, ViewGroup parent) {
      return getStandardView(position, parent, true);
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      return getStandardView(position, parent, false);
  }
  
  @Override
  public int getCount() {
      return count;
  }
  
  private View getStandardView(int position, ViewGroup parent, boolean dropdown) {
      View row = inflater.inflate(R.layout.support_simple_spinner_dropdown_item, parent, false);
  
      TextView title = (TextView) row.findViewById(android.R.id.text1);
  
      title.setText(String.valueOf(position + 1));
  
      if (dropdown)
          title.setMinWidth(Utils.dpToPx(getContext(), 64));
      else
          title.setAlpha(0.5f);
  
      return row;
  }
  }
  </code></pre>
  
  <p>In this way when i scroll the <code>RecyclerView</code> i'm experiencing lag.</p>
  
  <p><strong>If i remove these lines everything works fine:</strong></p>
  
  <pre><code>CartSpinnerAdapter adapter = (CartSpinnerAdapter) viewHolder.quantitySpinner.getAdapter();
  adapter.clear();
  adapter.setCount(((Article) object).getQuantityAvailable());
  adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>So the problem is the way i handle the adapter of the <code>Spinner</code>, how can i handle this?</p>
  
  <p>Thanks in advance.</p>