猿问
下载APP

类型转换异常

http://img2.mukewang.com/5e5411290001117b16940764.jpg


http://img2.mukewang.com/5e54114b0001e37516260711.jpg

测试Fragment代码

class TestFragment : MallFragment() {
    override fun setLayout(): Any {
        return R.layout.fragment_test
    }

    override fun onBindView(savedInstanceState: Bundle?, rootView: View) {
        Toast.makeText(context, "初始化完成", Toast.LENGTH_SHORT).show()
    }
}
class MainActivity : ProxyActivity() {

    override fun setRootFragment(): MallFragment {
        return TestFragment()
    }

}
ProxyActivity代码
abstract class ProxyActivity :
    AppCompatActivity(), ISupportActivity {
    private lateinit var mDelegate: SupportActivityDelegate
    abstract fun setRootFragment(): MallFragment

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mDelegate = SupportActivityDelegate(this)
        mDelegate.onCreate(savedInstanceState)
        initContainer(savedInstanceState)
    }

    private fun initContainer(savedInstanceState: Bundle?) {
        val container = FrameLayout(this)
        container.id = R.id.fragment_container
        setContentView(container)
        if (savedInstanceState == null) {
            mDelegate.loadRootFragment(
                R.id.fragment_container,
                setRootFragment()
            )
        }
    }

    override fun onDestroy() {
        mDelegate.onDestroy()
        super.onDestroy()
        System.gc()
        System.runFinalization()
    }

    override fun getSupportDelegate(): SupportActivityDelegate {
        return mDelegate
    }

    override fun post(runnable: Runnable?) {
        mDelegate.post(runnable)
    }

    override fun extraTransaction(): ExtraTransaction {
        return mDelegate.extraTransaction()
    }

    override fun getFragmentAnimator(): FragmentAnimator {
        return mDelegate.fragmentAnimator
    }

    override fun setFragmentAnimator(fragmentAnimator: FragmentAnimator) {
        mDelegate.fragmentAnimator = DefaultHorizontalAnimator()
    }

    override fun onCreateFragmentAnimator(): FragmentAnimator {
        return mDelegate.onCreateFragmentAnimator()
    }

    override fun onBackPressedSupport() {
        mDelegate.onBackPressedSupport()
    }

    override fun onBackPressed() {
        mDelegate.onBackPressed()
    }
}


雎山月
浏览 153回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答