I want to add youtube snippet to my existing snippets dynamically. The code I used below:
// setting the Youtube Player Dynamically private int setYoutubePlayer(String desc, View view, int prevID, Bundle input) { if (desc.indexOf("=") != -1) { desc = desc.substring(desc.indexOf("=") + "=".length()); } else { return prevID; } final String url = desc; LinearLayout videoLayout = new LinearLayout(view.getContext()); videoLayout.setOrientation(LinearLayout.VERTICAL); prevID++; videoLayout.setId(prevID); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragment.setVideoId(url); LinearLayout itemLayout = (LinearLayout) view.findViewById(R.id.items); itemLayout.addView(videoLayout); fragmentTransaction.add(itemLayout.getId(), fragment, "youtube fargment " + prevID); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); return prevID; }
I need to get the youtube fragment in the corresponding fragment. When I checked when a new fragment always loads (when scrolling between fragments), the new inner fragment should be the first loaded fragment.
Any help would be gladly accepted.
RESOLVED: Thank you, Kobe. You were right. I had to replace "getActivity (). getSupportFragmentManager ();" with "getChildFragmentManager ()". The problem was apparently in the Sherlock library with the old Android v4 support library. I had to update the support library in Sherlock. It worked for me .....
source share