There is activity , in it ViewPager and FloatingActionButton . I get a link to the fab in fragments of the view pager and put on it onClickListener , each fragment contains a unique id that needs to be processed in onClickListener . The problem is that in the handler, the id value is always null , although the fragment onCreate assigned a value and shows everything in the logs. I tried different options, and always the null variable in the handler. The fact is that a static variable cannot be made because the logic breaks, and the FloatingActionButton cannot be placed in fragments; it must be active. Is there a way out in this situation?

  • one
    Show the code relating to the question - we do not know what and how you are doing. If an active fragment must react to the FAB, the handler must be hung in it at the time of activation (it is necessary to watch the life cycle, I will not say the memory) - woesss
  • And why not prescribe a function with the same name in each fragment and just call it for the current fragment by pressing fab ? - Jarvis_J
  • I will throw off the code in a couple of hours. The value of the variable in this function will be null, due to the fact that the fab is in activity, as I understand it. Now the fragments inherit from the abstract fragment and implement the abstract getId () method, it is called in the handler and returns null. If you call it in onCreate when the isUserVisibleHint = true value is as expected, and in the handler it is always null and isUserVisibleHint = false is always. - Colibri
  • Solved the problem, thanks for the comments! - Colibri

0