从指挥调用 activity 方法
Call activity method from conductor
我有一个 Activity 和一个 zsmb:materialdrawer
和 conductor
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
}
}
我想从 conductor
调用我的 Activity
方法。
我正在尝试执行 mView.addDrawerItem()
但此方法在那里不可用。
据我所知,conductor
是片段的替代品,在 fragment
中,我可以通过 interface
轻松调用 activity
方法。在 conductor
中执行此操作的最佳做法是什么?
Conductor Controller 有一个 getActivity()
方法,就像 Fragments 一样。无论您使用的是 Controller 还是 Fragment,您都会这样做。
我有一个 Activity 和一个 zsmb:materialdrawer
和 conductor
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
}
}
我想从 conductor
调用我的 Activity
方法。
我正在尝试执行 mView.addDrawerItem()
但此方法在那里不可用。
据我所知,conductor
是片段的替代品,在 fragment
中,我可以通过 interface
轻松调用 activity
方法。在 conductor
中执行此操作的最佳做法是什么?
Conductor Controller 有一个 getActivity()
方法,就像 Fragments 一样。无论您使用的是 Controller 还是 Fragment,您都会这样做。