Antonello Gatto
Antonello Gatto

Reputation: 1611

Change fragment from clickable textview

I have fragments, in them I want to place custom textview, so I have not to define them everytime. So when I define the custom textview class I'd like to define a private onClickListener. When the user click on the textview the fragment will bu substituted. In the method onClick inside onClickLister i cannot invoke getFragmentManager. How can i do it?

Upvotes: 0

Views: 476

Answers (1)

Maxim Efimov
Maxim Efimov

Reputation: 2737

You have to do it manually as it's a really bad design - to bind item behaviour to objects it does not have to know about.

Just define a class, that implements OnClickListener the interface, getting the fragmentManager as a parameter of a constructor and perform all needed actions in this class. Then simply bind a listener's instance to the TextView in any object wich has a reference to a FragmentManager.

Upvotes: 1

Related Questions