Kotlin allows you to define functions as members of existing classes. These are called extension functions, and they are a great way to encapsulate boilerplate code that otherwise might be repeated many times.
- [Instructor] Kotlin allows you to define…and add functions to existing classes.…These are called extension functions…and they're a great way to encapsulate boilerplate code…that otherwise might have to be repeated many times.…You can define extension functions anywhere,…including in independent files.…I'll go to my base package in this project…and I'll create a new Kotlin file…that I'll name Extensions,…and I won't turn it into a class.…Now, to declare a function, I'll use the keyword fun…and then I'll start with the class…that I'm adding the function to.…
I'm going to add this to the view class from android.view.…Now, I can name my function and I'll call it flipVisibility.…The goal of this function is…to examine the current visibility setting…for a view that is a visual widget and then change it.…So, if it's visible, I'll make it invisible,…and if it's invisible, I'll make it visible.…I'll use some simple conditional logic.…I'll say if this.visibility…equals the constant View.VISIBLE,…then I want to make it invisible.…
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
Building Android Apps with Cloud Serviceswith Albert Lo2h 37m Intermediate
1. Android Development Tips Weekly
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.