0

我有一个 Activityzsmb:materialdrawerconductor

class MenuActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFailedListener{

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_menu)
        router = Conductor.attachRouter(this, container, savedInstanceState)
        if (!router.hasRootController()){
            router.setRoot(RouterTransaction.with(HomeController()))
        }
    }

    fun addDrawerItem() {
        // not implemented
    }

    private fun initViews(savedInstanceState: Bundle?) {
        toolbarMenu.setTitle(R.string.menu_title)

        drawerResult = drawer {

            primaryItem(getString(R.string.public_chats)){
                identifier = 101
                icon = R.drawable.abc_ic_star_black_48dp
                onClick(pushController(ChatRoomsController()))
            }
            primaryItem(getString(R.string.private_chats)){
                identifier = 102
                icon = R.drawable.abc_ic_star_black_48dp
                onClick(openActivity(ChatListActivity::class))
            }

        }
    }

}

class HomeController: Controller() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
        mView = inflater.inflate(R.layout.controller_sign_in, container, false)
        val signInWithGoogle = mView.findViewById<Button>(R.id.sign_in_with_google)
        signInWithGoogle?.setOnClickListener({
            // handle action with drawer here
            // mView.addDrawerItem()
        })
        return mView
    }
}

我想Activityconductor. 我正在尝试执行mView.addDrawerItem(),但此方法在那里不可用。据我所知conductor,它是一个片段的替代品,fragment我可以activity通过interface. 最好的做法是什么conductor

4

1 回答 1

0

导体控制器有一个getActivity()方法,就像片段一样。无论您使用的是控制器还是片段,您都会这样做。

于 2018-01-31T19:58:19.370 回答