Android Kotlin ActivityからFragmentを追加


supportFragmentManagerでlayoutにfragmentを割り当てる

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val fragment = MyFragment()
        val t = supportFragmentManager.beginTransaction()
        t.add(R.id.layout_id, fragment)
        t.commit()
    }
}