Мне необходимо в зависимости от чекбокса, выводить youtube или mediaplayer.
Из FrameLayout я подгружаю fragment1.xml или fragment2.xml
main xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox
android:id="@+id/chbStack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stack">
</CheckBox>
</LinearLayout>
<FrameLayout
android:id="@+id/frgmCont"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
MainActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frag1 = new Fragment1();
frag2 = new Fragment2();
chbStack = (CheckBox)findViewById(R.id.chbStack);
}
public void onClick(View v) {
fTrans = getFragmentManager().beginTransaction();
switch (v.getId()) {
case R.id.btnAdd:
fTrans.replace(R.id.frgmCont, frag1);
break;
case R.id.btnReplace:
fTrans.replace(R.id.frgmCont, frag2);
default:
break;
}
if (chbStack.isChecked()) fTrans.addToBackStack(null);
fTrans.commit();
}
Fragment1 - есть youtube плеер
public class Fragment1 extends Fragment implements YouTubePlayer.OnInitializedListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1, container, false);
YouTubePlayerFragment youtubePlayerFragment = new YouTubePlayerFragment();
youtubePlayerFragment.initialize("api_key", this);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frgmCont, youtubePlayerFragment);
fragmentTransaction.commit();
return view;
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo("EJylz_9KYf8");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
}
Проблема в том, что youtube плеер не инициализируется ;(