title: RecyclerView hide TextView inside Holder (Custom TV menu)
body: <p>I am creating a menu for my TV app, but since I couldn't get something like a NavigationDrawer working, I am using a RecyclerView with ImageButtons and TextViews. When the RecyclerView loses focus, I want to hide all the TextViews so that the RecyclerView collapses into a smaller menu. As an example you can look at the NetFlix sidemenu.</p>
  <p>Is there a better way than a RecyclerView?</p>
  <p>Currently everything is working except for the show/hide of the TextViews. My code:</p>
  <pre><code>        menuRecyclerView.onFocusChangeListener = View.OnFocusChangeListener { view, hasFocus -&gt;
              requireActivity().findViewById&lt;TextView&gt;(R.id.menuTextView)?.let {
                  if (hasFocus) {
                      it.visibility = View.VISIBLE
                  } else {
                      it.visibility = View.GONE
                  }
              }
          }
  </code></pre>
  <pre><code>class MenuItemAdapter(val context: Context, val menuItems: List&lt;MenuItemModel&gt;) : RecyclerView.Adapter&lt;MenuItemAdapter.MenuItemHolder&gt;() {
  
      var menuItemHolders : MutableList&lt;MenuItemHolder&gt; = mutableListOf()
  
      class MenuItemHolder(view: View, val context: Context) : RecyclerView.ViewHolder(view) {
  
          val imageButton: ImageButton = view.findViewById(R.id.menuImageButton)
          val textView: TextView = view.findViewById(R.id.menuTextView)
          val fragment = view
  
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MenuItemHolder {
          val mView: View = LayoutInflater.from(context).inflate(R.layout.menu_item, parent, false)
          return MenuItemHolder(mView, context)
      }
  
      override fun getItemCount() = menuItems.size
  
      override fun onBindViewHolder(holder: MenuItemHolder, position: Int) {
  
          val menuItem: MenuItemModel = menuItems[position]
  
          holder.imageButton.setImageDrawable(menuItem.icon)
  
          holder.textView.text = menuItem.text
  
          holder.imageButton.setOnClickListener {
              activeFragment.findNavController().navigate(menuItem.destination)
  
          }
  
          menuItemHolders.add(holder)
  
      }
  
  }
  </code></pre>
  <p>menu_item.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;&gt;
  
      &lt;androidx.cardview.widget.CardView
          android:id=&quot;@+id/cardView&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_margin=&quot;15dp&quot;
          android:background=&quot;@color/selected_card_background&quot;
          app:cardBackgroundColor=&quot;#00FFFFFF&quot;
          app:cardCornerRadius=&quot;0dp&quot;
          app:cardElevation=&quot;0dp&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:background=&quot;@drawable/card_background&quot;
              android:focusable=&quot;true&quot;
              android:focusableInTouchMode=&quot;true&quot;&gt;
  
              &lt;ImageButton
                  android:id=&quot;@+id/menuImageButton&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toTopOf=&quot;parent&quot;
                  app:layout_constraintEnd_toStartOf=&quot;@id/menuTextView&quot;
                  app:srcCompat=&quot;@drawable/baseline_home_24&quot; /&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/menuTextView&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:text=&quot;TextView&quot;
                  app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
                  app:layout_constraintStart_toEndOf=&quot;@id/menuImageButton&quot;
                  app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
      &lt;/androidx.cardview.widget.CardView&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>