Android call activity methods from fragment , fragment method from activity and fragment method from fragment in kotlin in Android

Android call activity methods from fragment , fragment method from activity and fragment method from fragment in kotlin in Android

1. Call activity method from fragment :

(activity as ActivityName).methodName()
ex:
(activity as MainActivity).userInfo()

2. Call fragment method from activity

  var fragment = supportFragmentManager.findFragmentById(R.id.content) 
  as UserInfoDetailsFragment
  fragment.userInfoDetails()

3. Call fragment method from fragment

UserProfileFragment().userProfile(context)

Leave a Reply

Your email address will not be published. Required fields are marked *