Извините за мой английский. Мне нужно динамически создавать YouTubePlayer, i cant распространяется на YoutubeBaseActivity. Поэтому мне нужно создать только YouTubePlayerSupportFragment. Я стараюсь делать это как этотСоздать YouTubePlayerSupportFragment programaticaly (android)
container_more_info_item - это мой LinearLayout
//create video
for(int j = 0; j < 5; j++) {
final YouTubePlayerSupportFragment ysF = new YouTubePlayerSupportFragment();
ysF.initialize("AIzbSyAT5C-xs5YG1HzG69Fn__PHq9DHXBuKpws", new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo("IjUlQU6yifk");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
//this line error, because ViewGroup can not be applied com.google.android.youtube.player.YouTubePlayerSupportFragment
container_more_info_item.addView(ysF);
}
И теперь я застрял. Не можете придумать что-то
UPD:
я использую FragmentManager, но у меня есть это сообщение Cannot resolve method 'add(int, com.google.android.youtube.player.YouTubePlayerSupportFragment)
//create video
for(int j = 0; j < 5; j++) {
final YouTubePlayerSupportFragment ysF = new YouTubePlayerSupportFragment();
ysF.initialize("AIzaSyAT5C-xs5YG1HzG69Fn__PHq9DHXBuKpws", new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo("IjUlQU6yifk");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
ll.setId(j);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragTransaction = fragmentManager.beginTransaction();
//Cannot resolve method 'add(int, com.google.android.youtube.player.YouTubePlayerSupportFragment)
fragTransaction.add(ll.getId(), ysF);
fragTransaction.commit();
container_more_info_item.addView(ll);
}
Чтобы добавить фрагмент, который вы должны использовать 'FragmentManager': https://developer.android.com/guide/components/fragments.html#Transactions –
@KenWolf спасибо за ваш комментарий, я обновляю свой вопрос. Пожалуйста, чекайте, я поступаю правильно? – g71132
Используйте 'getSupportFragmentManager()' вместо 'getFragmentManager()' –