![]() Imagine we have a ViewHolder that is holding a view with the layout described in the previous examples. This interface will provide the view that the plugin will use to find the subviews. The only required thing is that your class implements the interface LayoutContainer. You can now build a cache on any class in a simple way. Just go to your MainActivity and write it: override fun onCreate(savedInstanceState: Bundle?) Using it on a ViewHolder (or any custom class) Recovering views from the XMLįrom this moment, recovering a view is as easy as using the view id you defined in the XML directly into your activity.Īs you can see, the TextView has welcomeMessage id. You’re now ready to start working with it. Though the plugin comes integrated into the regular one (you don’t need to install a new one), if you want to use it you have to add an extra apply in the Android module: apply plugin: ''Īpply plugin: 'kotlin-android-extensions'Īnd that’s all you need. I’ll do this first example with an activity: Integrating Kotlin Android Extensions in our code But next times, the view will be recovered from the cache, so the access will be faster. So the first time a property is used, it will do a regular findViewById. The plugin will generate some extra code that will allow you to access views in the layout XML, just as if they were properties with the name of the id you used in the layout definition. Kotlin Android Extensions are another Kotlin plugin that is included in the regular one, and that will allow recovering views from Activities, Fragments, and Views in an amazing seamless way. If that’s your case, then you’ll love Kotlin Android Extensions. Or maybe you gave up and started using the famous Butterknife library. If you’ve been developing Android Apps for some time, you’re probably already tired of working with findViewById in your day-to-day life to recover views. ![]() Warning! Kotlin Android Extensions are deprecated, you should start using View Binding. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |