title: kotlin: how to pass a data between two fragments
body: <p>I have simple app that have one Activity , RecyclerView adapter , RecyclerView fragment , and other fragment to display the data of that item i click in RecyclerView but my problem is I don't know how to pass the data of array row with the click fun to show after the new fragment displayed</p>
  
  <p><strong>MainActivity.kt</strong></p>
  
  <pre><code>class MainActivity : AppCompatActivity(),ContentAdapter.ContentListener{
  override fun onItemClicked(item: MainMarketTickClass) {
          var ft1 : FragmentTransaction = supportFragmentManager.beginTransaction()
          ft1.replace(R.id.MainFrame,AddCar.newInstanceaddcar())
          ft1.commit()}
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
  
      setContentView(R.layout.activity_main)
      var bnv = findViewById(R.id.navigation) as BottomNavigationView
      bnv.setOnNavigationItemSelectedListener (object : BottomNavigationView.OnNavigationItemSelectedListener{
          override fun onNavigationItemSelected(item: MenuItem): Boolean {
              var selectFragment : Fragment? = null
              when (item.itemId) {
                  R.id.navigation_home -&gt; {
                      selectFragment = MainMarket.newInstance()
                  }
                  R.id.navigation_dashboard -&gt; {
                     selectFragment = AddCar.newInstanceaddcar()
                  }
                  R.id.navigation_notifications -&gt; {
  
                  }
              }
              var ft : FragmentTransaction = supportFragmentManager.beginTransaction()
              ft.replace(R.id.MainFrame,selectFragment)
              ft.commit()
              return true
          }
      })
  
      var ft : FragmentTransaction = supportFragmentManager.beginTransaction()
      ft.replace(R.id.MainFrame,MainMarket.newInstance())
      ft.commit()
  }
  
  }
  </code></pre>
  
  <p><strong>ContentAdapter.kt</strong></p>
  
  <pre><code>class ContentAdapter constructor(private val activity: MainActivity, private var listOfData: ArrayList&lt;MainMarketTickClass&gt;, val listener: ContentListener) : RecyclerView.Adapter&lt;ContentAdapter.ViewHolder&gt;() {
  
  override fun getItemCount(): Int = listOfData.size
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      var inf = ViewHolder(LayoutInflater.from(parent!!.context).inflate(R.layout.maintick, parent, false))
      return inf
  
  }
  
  override fun onBindViewHolder(holder: ViewHolder, position: Int) {
      holder.bind(listOfData, listener)
  }
  
  class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {
  
      fun bind(listOfData: ArrayList&lt;MainMarketTickClass&gt;, listener: ContentListener) {
          val dataListin2 = listOfData[adapterPosition]
  
          itemView.textView.text = dataListin2.title
  
         interface method implemented in the Activity
          itemView.setOnClickListener {
              listener.onItemClicked(listOfData.get(adapterPosition))
          }
      }
  }
  
  public interface ContentListener {
      fun onItemClicked(item: MainMarketTickClass)
  }
  </code></pre>
  
  <p><strong>MainMarket.kt</strong></p>
  
  <pre><code>class MainMarket: Fragment(),ContentAdapter.ContentListener{
  
  var ITEMSList = ArrayList&lt;MainMarketTickClass&gt;()
  companion object {
     fun newInstance():Fragment{
  
         var fb : MainMarket = MainMarket()
         return fb
     }
  }
  
  
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      var inf = inflater!!.inflate(R.layout.main_marker,container,false)
      return inf
  
  
  }
  
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  
      ITEMSList .add ( MainMarketTickClass("123"))
      ITEMSList .add ( MainMarketTickClass(" 123"))
      ITEMSList .add ( MainMarketTickClass("123"))
  
  
      var adapter = ContentAdapter (MainActivity(),ITEMSList,this)
      list.adapter = adapter
      list.layoutManager = LinearLayoutManager(this.context,LinearLayoutManager.VERTICAL,false)
  
  }
  
  override fun onItemClicked(item: MainMarketTickClass) {
      if(activity is MainActivity){
          (activity as MainActivity).onItemClicked(item)
  
      }
  
  }
  </code></pre>
  
  <p><strong>addcar.kt</strong></p>
  
  <pre><code>class AddCar: Fragment(), ContentAdapter.ContentListener{
  
  
  companion object {
     fun newInstanceaddcar(): Fragment {
  
         var fb : AddCar = AddCar()
         val args = Bundle()
  
         fb.arguments = args
  
         return fb
     }
  }
  
  
  
  
  
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      return inflater!!.inflate(R.layout.add_car,container,false)
  
  
  
  }
  
   override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
       val TextView= view!!.findViewById(R.id.textView) as TextView
       var titlein = ""
  
  }
  override fun onItemClicked(item: MainMarketTickClass) {
  
  
  }
  </code></pre>