alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Convert FindViewById to Binding in android ?

Convert FindViewById to Binding in android ?

Using the binding structure makes more sense now and saves you a lot of code. eg:if the activity was called HomeActivity it would be ActivityHomeBinding

build.gradle(module)

 buildFeatures {
        viewBinding true
        dataBinding true
    } 

MainActivity

 private lateinit var binding: ActivityMainBinding

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

        binding.apply {
         //eg:
         button.setOnClickListener{
           }
        }
    }

42 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online