Alex20280
Alex20280

Reputation: 365

SupportFragmentManager doesn't see view id

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>

Upvotes: 0

Views: 110

Answers (1)

z.g.y
z.g.y

Reputation: 6257

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

Upvotes: 0

Related Questions