SupportFragmentManager doesn't see view id

99 Views Asked by At

I try to use SupportFragmentManager for my fragments but I get an error. Is it a glitch or something? It doesn't see placeholder id that is located in mainactivity layout. R.id.placeHolder is red and it says unresolved reference placeHolder.

What can be a problem?

lateinit var binding: ActivityMainBinding
var counter: Int = 0

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)


    binding.redBtn.setOnClickListener {
        supportFragmentManager
            .beginTransaction()
            .add(R.id.placeHolder, FirstFragment())
            .commit()
        counter++
        binding.count.text = "$counter"
    }


}

}

<FrameLayout
    android:id="@+id/placeHolder"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@color/black"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</FrameLayout>
1

There are 1 best solutions below

0
On

These R reference issues most of the time can be solved by checking if you imported the correct R, or clean/rebuild/invalidate cache actions, if none works, you can delete .idea and/or .gradle generated folders inside the project directory and re-import the project as a gradle project as a last resort