Kotlin中的片段 [英] Fragment in kotlin
本文介绍了Kotlin中的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被卡在了我的应用程序中,因为我必须用Kotlin中的导航抽屉做一个片段.任何人都可以帮忙吗?我在网络上搜索了很多东西,但还没有找到任何东西... 下面是我在主要活动中所做的两项,我也希望该片段中也存在.
i'm stuck in my application because i have to do a fragment with the navigation drawer in kotlin.. can anyone help? I have search a lot of things in web but i didn't find anything yet... Down here is two items that i have do in main activity and i want that is present in the fragment too.
override fun onNavigationItemSelected(item: MenuItem): Boolean {
// Handle navigation view item clicks here.
when (item.itemId) {
R.id.home -> {
}
R.id.subjects -> {
val intent = Intent(this, SubjectsActivity::class.java)
startActivity(intent)
}
}
drawer_layout.closeDrawer(GravityCompat.START)
return true
}
推荐答案
您可以使用它用HomeFragment()替换框架 mainDisplayFrame应该替换为您的FrameID
You can use this to replace your frame with HomeFragment() mainDisplayFrame should be replace by your FrameID
var fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.mainDisplayFrame,HomeFragment()).commit()
mDrawerLayout!!.closeDrawers()
这篇关于Kotlin中的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文