I am trying to send information from fragment to the main activity.
I am trying to set a var interfaceName
in a fragment from the main activity.
I created var menuInterface: MenuInterface
and tried to set it in onNavigationItemSelected
using
myFragment.menuInterface = this
The menuInterface
stays null for some reason... any idea why?
the onNavigationItemSelected
override fun onNavigationItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.feedLayoutId -> {
feedFragment = FeedFragment()
feedFragment.menuInterface = this
barTitle.text = "myTitle"
supportFragmentManager
.beginTransaction()
.replace(R.id.frame_layout, feedFragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}
}
drawerLayout.closeDrawer(GravityCompat.START)
return true
}