title: How to cast a function set in fragment from Activity?
body: <p>I have a FAB button in my Activity the activity is made of a ViewPager which shows three fragments based on page.</p>
  <p>in each page the FAB should do something in the current fragment, like in the last fragment it should add an item and the function to add the item is in the fragment, but how can i cast it?</p>
  <p>Here is my activity code where i click on the FAB:</p>
  <p>class LetturaActivity : AppCompatActivity() {</p>
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_lettura) 
     // adding fragments to my ViewPager
  
     adapterView.addFragment(CorpoFragment())
     viewPager.adapter = adapterView
  
     fabNuovo.setOnClickListener {
          when(viewPager.currentItem){
              0 -&gt; {
                // click first fragment
              }
              1 -&gt; {
                // click second fragment
              }
              2 -&gt; {
                // click third fragment
              }
          }
  
      }
     }
  </code></pre>
  <p>}</p>
  <p>And i would execute the function</p>
  <pre><code>private fun addArticolo() {
    val barcode = txtBarcode.text.toString()
      val qta = txtQta.text.toString().toFloat()
  
  
      if (barcode.isEmpty()) {
          txtBarcode.requestFocus()
          return
      }
     ...
   } 
  </code></pre>
  <p>which is in my CorpoFragment..</p>
  <p>How should i do it?</p>
  <p>I've tried to do it with the interface but instead i get nullpointers which says that my edittexts are null and other stuff while the fragment is initialized...</p>