我想动态地将youtube片段添加到我已经存在的片段中.我使用的代码如下:
// setting the Youtube Player Dynamicallyprivate 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;}
我需要在适当的片段中获取youtube片段.当我检查总是加载一个新片段时(当在片段之间滑动时),新的内部片段需要是第一个加载的片段.
任何帮助都会很乐意接受.
解决:谢谢你Koby你是对的.我不得不替换“getActivity().getSupportFragmentManager();”使用“getChildFragmentManager()”.问题显然是Sherlock库附带了一个旧的androID v4支持库.我不得不更新Sherlock中的支持库.它对我有用…..
@H_404_16@最佳答案要在片段内创建嵌套片段,您应该使用:http://developer.android.com/reference/android/app/Fragment.html#getChildFragmentManager()
从父片段调用getChildFragmentManager(),
并在父项中执行事务以将子项嵌套在其中.
https://stackoverflow.com/a/13381825/1693674
告诉我你是否需要更多帮助…
总结以上是内存溢出为你收集整理的android – 将片段添加到片段中(嵌套片段)全部内容,希望文章能够帮你解决android – 将片段添加到片段中(嵌套片段)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)