0

How can I set a TAG for fragment that is created like this:

@Override
public Fragment getItem(int position) {
    // getItem is called to instantiate the fragment for the given page.
    // Return a PlaceholderFragment (defined as a static inner class below).
    switch (position) {
        case 0: return new scanFragment();
        case 1: return new shopingListFragment();
        case 2: return new PayOnlineFragment();
    }
    return new scanFragment();
}

I want to set a TAG to be able to communicate between fragments using interfaces.

A_Matar
  • 2,210
  • 3
  • 31
  • 53
  • http://stackoverflow.com/questions/6374170/how-to-set-a-fragment-tag-by-code – mrak Jul 10 '15 at 09:05
  • @mrak I checked this post before I asked, still didn't help. I am not using fargments with xml nor do they have a name so that I can refer to them when using sth like: beginTransaction() – A_Matar Jul 10 '15 at 09:21

1 Answers1

0

The documentation of the Fragment class does not expose any setter for the tag. See http://developer.android.com/reference/android/app/Fragment.html

However a Fragment always has a tag (at least once they are attached, maybe earlier im'm not sure). So you can use getTag() to get the tag of your fragment and use it to communicate with it.

sonic
  • 1,894
  • 1
  • 18
  • 22