title: On Click function not behaving as expected; confused as to why? (Android Studio, RecyclerView)
body: <p>Ok I've been pondering this all weekend and I'm running in circles and confusing myself about it; so someone please help. Here's the scoop: I have an app with a RecyclerView to hold CardView items. Here is the layout:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.cardview.widget.CardView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:id=&quot;@+id/scene_container&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      app:cardCornerRadius=&quot;4dp&quot;
      app:cardBackgroundColor=&quot;#75757A&quot;&gt;
  
      &lt;RelativeLayout
          android:id=&quot;@+id/listItemWrapper&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_margin=&quot;4dp&quot;&gt;
  
          &lt;TextView
              android:id=&quot;@+id/assetSymbol&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_margin=&quot;8dp&quot;
              android:text=&quot;SYM&quot;
              android:textColor=&quot;@android:color/white&quot;
              android:textSize=&quot;20sp&quot;
              android:textStyle=&quot;bold&quot;&gt;
          &lt;/TextView&gt;
  
          &lt;TextView
              android:id=&quot;@+id/assetPrice&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_margin=&quot;8dp&quot;
              android:layout_toEndOf=&quot;@+id/assetSymbol&quot;
              android:text=&quot;$1,000.00&quot;
              android:textColor=&quot;@android:color/white&quot;
              android:textSize=&quot;20sp&quot;
              android:textStyle=&quot;bold&quot;
              android:layout_toRightOf=&quot;@+id/assetSymbol&quot;&gt;
          &lt;/TextView&gt;
  
          &lt;ImageView
              android:id=&quot;@+id/imageView&quot;
              android:layout_width=&quot;30sp&quot;
              android:layout_height=&quot;30sp&quot;
              android:layout_margin=&quot;8dp&quot;
              android:layout_toEndOf=&quot;@+id/assetPrice&quot;
              android:padding=&quot;2dp&quot;
              android:layout_toRightOf=&quot;@+id/assetPrice&quot;&gt;
          &lt;/ImageView&gt;
  
          &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
              android:id=&quot;@+id/openShort&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_below=&quot;@+id/assetPrice&quot;
              android:layout_alignParentEnd=&quot;true&quot;
              android:layout_alignParentRight=&quot;true&quot;
              android:layout_marginEnd=&quot;8dp&quot;
              android:layout_marginRight=&quot;8dp&quot;
              android:backgroundTint=&quot;@color/bearRed&quot;
              android:clickable=&quot;true&quot;
              android:visibility=&quot;gone&quot;
              app:fabSize=&quot;mini&quot;
              app:srcCompat=&quot;@drawable/ic_bear_enter&quot; /&gt;
  
          &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
              android:id=&quot;@+id/openLong&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_below=&quot;@+id/assetPrice&quot;
              android:layout_marginEnd=&quot;16dp&quot;
              android:layout_marginRight=&quot;16dp&quot;
              android:layout_toStartOf=&quot;@+id/openShort&quot;
              android:layout_toLeftOf=&quot;@+id/openShort&quot;
              android:backgroundTint=&quot;@color/bullGreen&quot;
              android:clickable=&quot;true&quot;
              android:visibility=&quot;gone&quot;
              app:fabSize=&quot;mini&quot;
              app:srcCompat=&quot;@drawable/ic_bull_enter&quot; /&gt;
  
          &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
              android:id=&quot;@+id/deleteAsset&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_below=&quot;@+id/assetPrice&quot;
              android:layout_marginEnd=&quot;16dp&quot;
              android:layout_marginRight=&quot;16dp&quot;
              android:layout_toStartOf=&quot;@+id/openLong&quot;
              android:layout_toLeftOf=&quot;@+id/openLong&quot;
              android:backgroundTint=&quot;@color/colorPrimary&quot;
              android:clickable=&quot;true&quot;
              android:visibility=&quot;gone&quot;
              app:fabSize=&quot;mini&quot;
              app:srcCompat=&quot;@drawable/ic_delete_asset&quot; /&gt;
  
          &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
              android:id=&quot;@+id/editAsset&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_below=&quot;@+id/assetPrice&quot;
              android:layout_marginEnd=&quot;16dp&quot;
              android:layout_marginRight=&quot;16dp&quot;
              android:layout_toStartOf=&quot;@+id/deleteAsset&quot;
              android:layout_toLeftOf=&quot;@+id/deleteAsset&quot;
              android:backgroundTint=&quot;@color/colorPrimary&quot;
              android:clickable=&quot;true&quot;
              android:visibility=&quot;gone&quot;
              app:fabSize=&quot;mini&quot;
              app:srcCompat=&quot;@drawable/ic_edit_asset&quot; /&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/showOptions&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;32dp&quot;
          android:layout_gravity=&quot;end&quot;
          android:layout_margin=&quot;8dp&quot;
          app:srcCompat=&quot;@drawable/ic_baseline_more_vert&quot; /&gt;
  
  &lt;/androidx.cardview.widget.CardView&gt;
  </code></pre>
  <p>You'll notice that the card contains four floating action buttons, which are initially hidden. What I'm trying to do is have the buttons animate into view when the user clicks the &quot;show options&quot; ImageView (android:id=&quot;@+id/showOptions&quot;). Here is all the relevant code snippets:</p>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>public class MainActivity extends AppCompatActivity implements OnClickListener {
  
      private ArrayList&lt;WatchListItem&gt; watchListArray;
      private RecyclerView watchList;
      private WatchListAdapter listAdapter;
      private RecyclerView.LayoutManager listManager;
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          watchListArray = new ArrayList&lt;&gt;();
          watchList = (RecyclerView) findViewById(R.id.watchList);
          watchList.setHasFixedSize(true);
          listManager = new LinearLayoutManager(this);
          watchList.setLayoutManager(listManager);
          listAdapter = new WatchListAdapter(watchListArray);
          watchList.setAdapter(listAdapter);
      }
  
      public void engage(Asset asset) {
          int position = watchListArray.size();
          String ticker = asset.getSymbol();
          //Double.toString(asset.getCurrentPrice()) replaced with fixed value for testing
          String price = &quot;390.55&quot;;
          //int indicator set to fixed value for testing
          int indicator = R.drawable.ic_bull_indicator;
          watchListArray.add(position, new WatchListItem(indicator, price, ticker));
          listAdapter.notifyItemInserted(position);
          listAdapter.setOnItemClickListener(new WatchListAdapter.OnItemClickListener() {
              @Override
              public void onShowOptionsClick(int position, ImageView show, FloatingActionButton edit, FloatingActionButton delete, FloatingActionButton oLong, FloatingActionButton oShort) {
                  expandListItem(position, show, edit, delete, oLong, oShort);
              }
          });
      }
  
      public void expandListItem(int position, ImageView show, FloatingActionButton edit, FloatingActionButton delete, FloatingActionButton oLong, FloatingActionButton oShort) {
          if (edit.getVisibility() == View.GONE) {
              show.setImageResource(R.drawable.ic_collapse);
              oShort.animate().alpha(1f).setDuration(150);
              oLong.animate().alpha(1f).setStartDelay(125).setDuration(150);
              delete.animate().alpha(1f).setStartDelay(250).setDuration(150);
              edit.animate().alpha(1f).setStartDelay(375).setDuration(150);
          } else {
              edit.animate().alpha(0f).setDuration(150);
              delete.animate().alpha(0f).setStartDelay(125).setDuration(150);
              oLong.animate().alpha(0f).setStartDelay(250).setDuration(150);
              oShort.animate().alpha(0f).setStartDelay(375).setDuration(150);
              show.setImageResource(R.drawable.ic_baseline_more_vert);
          }
          listAdapter.notifyItemChanged(position);
      }
  </code></pre>
  <p><strong>WatchListAdapter.java</strong></p>
  <pre><code>public class WatchListAdapter extends RecyclerView.Adapter&lt;WatchListAdapter.WatchListViewHolder&gt; {
      private ArrayList&lt;WatchListItem&gt; mWatchList;
      private OnItemClickListener mListener;
  
      public interface OnItemClickListener {
          void onShowOptionsClick(int position, ImageView show, FloatingActionButton edit, FloatingActionButton delete, FloatingActionButton oLong, FloatingActionButton oShort);
      }
  
      public void setOnItemClickListener(OnItemClickListener listener) {
          mListener = listener;
      }
  
      public static class WatchListViewHolder extends RecyclerView.ViewHolder {
          public TextView mAssetSymbol;
          public TextView mAssetPrice;
          public ImageView mImageView;
          public ImageView mShowOptions;
          public FloatingActionButton mEditAsset;
          public FloatingActionButton mDeleteAsset;
          public FloatingActionButton mOpenLong;
          public FloatingActionButton mOpenShort;
  
          public WatchListViewHolder(@NonNull View itemView, final OnItemClickListener listener) {
              super(itemView);
              mAssetSymbol = itemView.findViewById(R.id.assetSymbol);
              mAssetPrice = itemView.findViewById(R.id.assetPrice);
              mImageView = itemView.findViewById(R.id.imageView);
              mShowOptions = itemView.findViewById(R.id.showOptions);
              mEditAsset = itemView.findViewById(R.id.editAsset);
              mDeleteAsset = itemView.findViewById(R.id.deleteAsset);
              mOpenLong = itemView.findViewById(R.id.openLong);
              mOpenShort = itemView.findViewById(R.id.openShort);
  
              mShowOptions.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      if (listener != null) {
                          int position = getAdapterPosition();
                          ImageView show = mShowOptions;
                          FloatingActionButton edit = mEditAsset;
                          FloatingActionButton delete = mDeleteAsset;
                          FloatingActionButton oLong = mOpenLong;
                          FloatingActionButton oShort = mOpenShort;
                          if (position != RecyclerView.NO_POSITION) {
                              listener.onShowOptionsClick(position, show, edit, delete, oLong, oShort);
                          }
                      }
                  }
              });
          }
      }
  
      public WatchListAdapter(ArrayList&lt;WatchListItem&gt; watchListArray) {
          mWatchList = watchListArray;
      }
  
      @NonNull
      @Override
      public WatchListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
          return new WatchListViewHolder(v, mListener);
      }
  
      @Override
      public void onBindViewHolder(@NonNull WatchListViewHolder holder, int position) {
          WatchListItem currentItem = mWatchList.get(position);
          holder.mAssetSymbol.setText(currentItem.getAssetSymbol());
          holder.mAssetPrice.setText(currentItem.getAssetPrice());
          holder.mImageView.setImageResource(currentItem.getImageResource());
      }
  
      @Override
      public int getItemCount() {
          return mWatchList.size();
      }
  }
  </code></pre>
  <p><strong>WatchListItem.java</strong></p>
  <pre><code>public class WatchListItem {
      private int mImageResource;
      private String mAssetPrice;
      private String mAssetSymbol;
  
      public WatchListItem(int imageResource, String assetPrice, String assetSymbol) {
          mImageResource = imageResource;
          mAssetPrice = assetPrice;
          mAssetSymbol = assetSymbol;
      }
  
      public int getImageResource() {
          return mImageResource;
      }
  
      public String getAssetPrice() {
          return mAssetPrice;
      }
  
      public String getAssetSymbol() {
          return mAssetSymbol;
      }
  }
  </code></pre>
  <p><em>Quick note about the placement of listAdapter.setOnItemClickListener in MainActivity.java: initially this was included in the onCreate() method because that is where the RecyclerView is built and also where it was placed in the tutorial I was trying to follow; but I moved it to the engage() method because this is where the list item is added and I figured it didn't make sense to set the listener before the item even existed, right? Anyway let me know if this is incorrect, as I suspect it is, though regardless this did not change the behavior in testing</em>
  So here's the problem: App opens just fine, adds the item to the RecyclerView, but when I click the dropdown ImageView, nothing. Well not exactly nothing, I can tell it's trying to do something, but ultimately nothing happens. The best way I can describe it is that the CardView kind of &quot;flashes&quot; and the ImageView icon is briefly changed to the new icon but instantly changes back, and that's it. No errors, no crashes; just not performing the specified action and I cannot figure out why. I don't know why they had to deprecate ListView because this all would be a lot less confusing to me if I didn't have to build the onClickListener interface from scratch, but I digress. Thank you so much for taking the time to read all this and offering your valuable input.</p>