如何在同一活动中一起使用“ YouTubeBaseActivity”和“ getSupportFragmentManager()”

时间:2019-08-23 07:47:42

标签: java android android-fragments youtubeplayer

我正在做一个布局,因为我必须实现youtube播放器和tabelayout,所以对于选项卡布局,我需要一个FragmentStatePagerAdapter,而构造函数参数是fragment manager,因此我必须传递getSupportFragmentManager()。但是我在YouTubeBaseActivity中使用getSupportFragmentManager()时遇到了问题。

public class DetailPage extends YouTubeBaseActivity {

TabLayout tabLayout;
ViewPager detailPageViewPager;
TextView pageTitle, changelanguageText;
ImageView imageOfVideoPlayer;
YouTubePlayer youtubeVideoPlayer;

DetailPagerAdapter pagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail_page);

    init();
    pagerAdapter = new DetailPagerAdapter(getSupportFragmentManager());
    detailPageViewPager.setAdapter(pagerAdapter);
}

private void init() {
    tabLayout = findViewById(R.id.tabLayout);
    detailPageViewPager = findViewById(R.id.detailPageViewPager);
    pageTitle = findViewById(R.id.pageTitle);
    changelanguageText = findViewById(R.id.changelanguageText);
    imageOfVideoPlayer = findViewById(R.id.imageOfVideoPlayer);
    youtubeVideoPlayer = findViewById(R.id.youtubeVideoPlayer);

}

public void finish(View view) {
    super.onBackPressed();
}


public static class MyFragment extends Fragment{

    public MyFragment() {
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        TextView textView = new TextView(getActivity());
        textView.setText("This Fragment Text");
        textView.setGravity(Gravity.CENTER);
        return textView;
    }
}

}

0 个答案:

没有答案