ViewBinding: Creating BaseClasses 🛠

👨🏻‍💻 How to create base-class of Activities and Fragment

Note this post is just one fraction of the ViewBinding Deep Dive I did on my personal blog. If you find it useful do consider checking-out the full In-depth article.

Creating BaseActivity


Creating BaseFragment


That’s it! copy these snippets and you will have ready-to-use ViewBinding Classes in your codebase.

It’s not just Another ViewBinding Article 👇🏻

TLDR: You will Learn

There are many view binding articles out now, what values does it add? after completing this one you would be familiar with these points

  • View-binding not working in all the modules? Why your fields are not getting generated?
  • How to view the source code of your generated binding classes?
  • Generated classes are Kotlin or Java? and why?
  • Do View-binding views are never null?
  • How to access included views? <include> and <merge> tags?
  • How to bind Activities, Fragments, Adapters, and CustomViews?
  • When to use bind and Inflate?
  • Controlling ViewBinding Generation?
  • Reducing boilerplate code with Delegates and Base-Class for ViewBinding in Activity and Fragments?
  • Common mistakes and Anti-patterns in ViewBinding?

Until next time. Happy Hacking! 👩‍💻

Read Next

Stalk Me 👀 :

LinkedIn | Twitter | StackOverflow | Github | Youtube | WorkX | About Me



A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chetan Gupta

Chetan Gupta

Coding enthusiast! love Android #kotlinAlltheWay, want to explore all opportunity around it! CodingMantra: #cleanCoder #TDD #SOLID #designpatterns