Fragment Transactions with transition – Unique transitionNames are required

I want to go from a list view to the detail view and therefore, I use following OnClickListener in my list:

public void onClick(View view)
    Bet bet = (Bet)view.getTag();
    FragmentManager fm = getActivity().getSupportFragmentManager();
    BetDetailFragment f = BetDetailFragment.create(bet);
    String tag = f.getClass().getName();


    FragmentTransaction ft = fm.beginTransaction()
            .replace(, f, tag)

        L.d(this, "TRANS: " + TransitionUtil.getTransitionNameBetLogo1(bet) + "|" + view.findViewById(;
        L.d(this, "TRANS: " + TransitionUtil.getTransitionNameBetLogo2(bet) + "|" + view.findViewById(;
        ft.addSharedElement(view.findViewById(, "1");//TransitionUtil.getTransitionNameBetLogo1(bet));
        ft.addSharedElement(view.findViewById(, "2");//TransitionUtil.getTransitionNameBetLogo2(bet));

My functions return unique names, I have two different views, but still it does not work.
I already commented unnecessary functions out and wrote some unique transaction names in there by hand… But still, I get this exception, in the line of the first addSharedElement:

  • Android SearchView in Toolbar
  • How to start an Intent if context is not Activity Context but Application Context
  • Why does Android prefer static classes
  • Xamarin.Forms ListView: Set the highlight color of a tapped item
  • Android NDK: Your APP_BUILD_SCRIPT points to an unknown file
  • Android - Send Telegram message to a specific number
  • java.lang.IllegalArgumentException: Unique transitionNames are required for all sharedElements


    Without the shared elements, everything is working perfectly fine…

    Related posts:

    Floating Action Button attached with anchor not hiding when scrolling RecyclerView items slow
    How to get the frame from video file in android
    Converting yyyy-mm-dd into dd mm yyyy
    Android studio- “SDK tools directory is missing”
    Genymotion Emulator : Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
    Job Scheduler not running on Android N
  • Get only email address from contact list Android
  • Google Drive Android API - Check if folder exists
  • Gson deserialization of List<String> into realmList<RealmString>
  • Is it possible to enter debug mode for android when running junit test?
  • Android Broadcast Receiver bluetooth events catching
  • How does push notification technology work on Android?
  • 2 Solutions collect form web for “Fragment Transactions with transition – Unique transitionNames are required”

    The problem is, that addSharedElement does NOT set the transaction name of the view!

    So in my example I would have to set it with following code:

    ViewCompat.setTransitionName(view.findViewById(, "1");
    ViewCompat.setTransitionName(view.findViewById(, "2");

    BEFORE I add this views to the FragmentTransaction

    Afterwards following works just fine and as expected:

    ft.addSharedElement(view.findViewById(, "1");
    ft.addSharedElement(view.findViewById(, "2");

    If your onClickListener is part of your fragment, not parent Activity, then you are doing things wrong here. Your fragment should notify parent activity what it wants and Activty should deal with it (i.e. by replacing fragments etc). Fragment should never do this by itself. Also if all you need is to go from detail view to list, then I assume you entered your detail view from that list. If so, all you need is to pop last element (fragment view fragment) fromt back stack. See:

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.