Hi. I try to create a bottom menu with fragment. But the code has some error. Im new in this word of programation.
If someone could guide me I would be grateful
package com.example.splashscreen
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
class Principal : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_principal)
var InicioFragment = InicioFragment()
var mercadoFragment = mercadoFragment()
var noticiasFragment = noticiasFragment()
var senalesFragment = senalesFragment()
var tutorialesFragment = tutorialesFragment()
**bottomNavigationView**.setOnNavigationItemSelectedListener {**it**: MenuItem
when(**it**.itemId){
R.id.nav_inicio -> {
setcurrentFragment(InicioFragment)
}
R.id.nav_mercado -> {
setcurrentFragment(mercadoFragment)
}
R.id.nav_noticias -> {
setcurrentFragment(noticiasFragment)
}
R.id.nav_senales -> {
setcurrentFragment(senalesFragment)
}
R.id.nav_tutoriales -> {
setcurrentFragment(tutorialesFragment)
}
else -> false
} }
}
private fun setcurrentFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction().apply { this: FragmentTransaction
replace(R.id.containerView, Fragment)
commit()
}
}
}
Thx so much.