How to write variable of activity that contains fargment class from inside
current Fragment?
i have an activity with indefinite number of fragments. Inside fragments
there is a variable that need to access in the activity to call an intend
from activity bar correctly. But only the variable of the current fragment
is on screen. This is because the call depends of the fragment you are.
Due to fragment manager creates three fragment at a time can't write a
variable calling from inside fragment because i don't know who is the last
that writes variable. Need to identify the fragment is displayed. I tried
from inside to control visibility overriding setUserVisibleHint(boolean b)
and write variable when true but same happends. not guaranteed that the
current fragment is the last writting. I also tried getting the current
fragment from activity to call fragment method and get this variable. But
is difficult to identify current fragment. I tried this:
getsupportFragmentManager().findFragmentByTag("android:switcher:"+R.id.myViewPager+":"+myViewPager.getCurrentItem()).getVariable();
But have null Pointer Exception.
Thanks for suggestions!
No comments:
Post a Comment