title: How can I get Activity from RecyclerView.ViewHolder(itemView) in Android Studio 3.5.2?
body: <p>The function <code>Navigation.findNavController()</code> need a <code>Activity</code> parmater in Code A, but I can only get a <code>context</code> via <code>itemView.context</code>.</p>
  
  <p>How can I get <code>Activity</code> from  <code>RecyclerView.ViewHolder(itemView)</code> in Android Studio ?</p>
  
  <p>At present, I have to pass <code>private val mActivity: Activity</code> from Code B to Code A, it works, but I think it's not a good way.</p>
  
  <p><strong>Added content:</strong></p>
  
  <p>To Miriana Itani: Thanks! </p>
  
  <p>Your code works well. I paste FrameLayout xml file, you can see Code C</p>
  
  <p>I'm very strange how the code <code>Navigation.findNavController(temView)...</code> find the NavController control? <strong>Could you tell me</strong>?</p>
  
  <p>You know it's easy to understand to use the code <code>Navigation.findNavController(mActivity, R.id.fragment_container)</code>, because the ID of NavController is <code>fragment_container</code>, and it's unique.</p>
  
  <p><strong>Code A</strong></p>
  
  <pre><code>class VideoListAdapter (private val videoList: List&lt;File&gt;, private val mActivity: Activity) : RecyclerView.Adapter&lt;VideoListAdapter.MyViewHolder&gt;() {
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VideoListAdapter.MyViewHolder {
          val v = LayoutInflater.from(parent.context).inflate(R.layout.layout_fragment_video_list_recycleview, parent, false)
          return MyViewHolder(v)
      }
  
      override fun onBindViewHolder(holder: VideoListAdapter.MyViewHolder, position: Int) {
          holder.bindItems(videoList[position])
      }
  
      override fun getItemCount(): Int {
          return videoList.size
      }
  
      inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  
          fun bindItems(aFile: File) {           
              itemView.tvVideoFileName.text=aFile.name
              itemView.btnPlay.setOnClickListener {
                  Navigation.findNavController(mActivity, R.id.fragment_container).navigate(
                      UIFragmentVideoListDirections.aVideoList2Video((aFile.absolutePath)) )
  
              }
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Code B</strong></p>
  
  <pre><code>class UIFragmentVideoList : Fragment() {
  
      private lateinit var listFile: MutableList&lt;File&gt;
  
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                                savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.layout_fragment_video_list, container, false)
  
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
  
          val outputDirectoryOfVideo = getVideoOutputDirectory(requireContext())
          listFile =outputDirectoryOfVideo.listFiles{file -&gt; VIDEO_EXTENSION_WHITELIST.contains(file.extension.toUpperCase())}
                     .sorted().reversed().toMutableList()
  
          videoRecyclerView.layoutManager =  LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false)
          val aVideoListAdapter=VideoListAdapter(listFile,requireActivity())
          videoRecyclerView.adapter=aVideoListAdapter
  
      }
  
  }
  </code></pre>
  
  <p><strong>Code C</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
      &gt;
  
      &lt;fragment
              android:id="@+id/fragment_container"
              android:name="androidx.navigation.fragment.NavHostFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:defaultNavHost="true"
              app:navGraph="@navigation/nav_graph" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>