Search code examples
androidandroid-fragmentsandroid-actionbarandroid-fragmentactivityandroid-tabs

ActionBar swipeable tabs + communication between tabs


I saw a lot of posts about the communication between fragments and activity. I chose to create getters and setters in my activity so i can get and set the data i want to share in my 3 tabs.
But when i use getActivity.getData(); i got a "The method getData() is undefined for the type FragmentActivity" message.
I use getActivity in the onAttach() method.
Thank you for reading


Solution

  • usually this happens because the getActivity() does not have to return your "Main" Activity. If your Activity is called "MainActivity" the cast it just like this:

    (MainActivity)getActivity().getData();
    

    Hope this helps ;)