Dariush Fathi
Dariush Fathi

Reputation: 1695

how to detect activity button click in fragment?

Only thing that i want is to detect button click in fragments .

enter image description here

Upvotes: 0

Views: 1151

Answers (2)

Vucko
Vucko

Reputation: 7479

There are many ways to interact between fragments and activities, and you can find them by searching here on SO, but the easiest way I've found so far and the one I love using the most is a 3rd party library, called EventBus.

You can simply post an event on button click, custom event which can carry all kinds of data, and then in your fragment, simply write a method that listens for that event and does whatever is necessary.

Upvotes: 1

Javier Delgado
Javier Delgado

Reputation: 2383

If your button is interacting with your fragment, it should not be separated.

However, you can do:

getActivity().findViewById(...)

inside your fragment

Upvotes: 1

Related Questions