skip to Main Content
        bottomNavigationView.setOnNavigationItemSelectedListener{
            when (it.itemId){

                R.id.local1 -> make_Fragment(fragment1)
                R.id.local2-> make_Fragment(fragment2)
                R.id.local3 -> make_Fragment(fragment3)
            }
            true

     }

Here bottomNavigationView is throwing error : Unresolved reference: bottomNavigationView and also i defined the id on mainactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".main.MainActivity">


<FrameLayout
    android:id="@+id/fl_wapper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/bottomNavigationView"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_nav"
        />


</RelativeLayout>

Here bottomNavigationView shows error and also when(it.itemId){
the bottomNavigationView is the id of the bottom bar.i also tried clean project and rebuild project.

tell me a solution to resolve this problem?

2

Answers


  1. Chosen as BEST ANSWER

    add these in build.gradle(:app)

       id 'kotlin-android'
       id 'kotlin-android-extensions'
    

    this in dependencies implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" like this

    dependencies {
    
        implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" }
    

    add this import statement in MainActivity.kt

    import kotlinx.android.synthetic.main.mainactivity.*
    

    it will work just fine :)...


  2. Add this dependencies in build.gradle

    implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
    

    Add kotlin code implementation
    Please refer this my github repository for better understanding.

    https://github.com/meshramaravind/BottomNavigtaionApp

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search