200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > android 片段 android – 将片段添加到片段中(嵌套片段)

android 片段 android – 将片段添加到片段中(嵌套片段)

时间:2018-06-01 13:27:10

相关推荐

android 片段 android  – 将片段添加到片段中(嵌套片段)

我想动态地将youtube片段添加到我已经存在的片段中.我使用的代码如下:

// 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);

mit();

return prevID;

}

我需要在适当的片段中获取youtube片段.当我检查总是加载一个新片段时(当在片段之间滑动时),新的内部片段需要是第一个加载的片段.

任何帮助都会很乐意接受.

解决:谢谢你Koby你是对的.我不得不替换“getActivity().getSupportFragmentManager();”使用“getChildFragmentManager()”.问题显然是Sherlock库附带了一个旧的android v4支持库.我不得不更新Sherlock中的支持库.它对我有用…..

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。