Home > Blockchain >  How to pass a button click from Fragment that is in a BottomSheet Toolbar to the Main Activity?
How to pass a button click from Fragment that is in a BottomSheet Toolbar to the Main Activity?

Time:12-02

I have implemented a TabLayout (which uses fragments) in my bottom sheet toolbar that has buttons which should affect the Main Activity. How do I pass the button clicks from the fragments in my TabLayout to the Main Activity?

I'm stuck and I don't know where to start.

CodePudding user response:

I think You need to create a function in MainActivity And call that function in the fragment. You can easily access that function bcoz it is your parent activity so you can use it on the button.

References: I know this is in java but I think it's helpful for you link

CodePudding user response:

There are multiple methods to do communication between fragments and its activity . I'll explain the ones which are used widely.

  1. Using an interface.
  2. Using a SharedViewModel for all your fragments and its activity . ( this can be used if you are implementing MVVM architecture )

check this out link

  • Related