Kotlin不允许多重继承。我该怎么做?

时间:2018-09-21 19:47:24

标签: android inheritance kotlin

class MainActivity : YouTubeBaseActivity() ,AppCompatActivity() (error:multiple inheritance)  {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // attaching layout xml
    setContentView(R.layout.activity_main)
    val adapter = PagerAdapter(supportFragmentManager)
    val pager = findViewById<View>(R.id.pager) as ViewPager

    pager.adapter = adapter

    // Initializing YouTube player view
    val youTubePlayerView = findViewById(R.id.youtube_player_view) as YouTubePlayerView
    youTubePlayerView.initialize("YOUR API KEY",
            object : YouTubePlayer.OnInitializedListener {
                override fun onInitializationSuccess(provider: YouTubePlayer.Provider,
                                                     youTubePlayer: YouTubePlayer, b: Boolean) {

                    // do any work here to cue video, play video, etc.
                    youTubePlayer.cueVideo("5xVh-7ywKpE")
                }

                override fun onInitializationFailure(provider: YouTubePlayer.Provider,
                                                     youTubeInitializationResult: YouTubeInitializationResult) {

                }
            })

}

在此应用程序中,我将YoutubeViewViewPager一起使用。我收到错误消息,因为我无法使用AppCompatActivity().supporFragmentManager(error)

Kotlin不支持多重继承。我该怎么办?

1 个答案:

答案 0 :(得分:2)

您不应在Avtivity中扩展FragmentManager。活动已经包含fragmentManager的实例,因此您可以像getFragmentManager()一样获得它,而在Kotlin中,它只是fragmentManager