In this video, take a look a few more extension functions that are really helpful in your Android apps. Learn how to reuse common code across your files as well as how to create an extension function with a lambda parameter.
- [Instructor] Let's take a look…at a few more extension functions…that you'll find really helpful i0n your Android apps.…For this,…we're going to update the Planet Detail Activity class.…And we'll start here with the onCreate method.…Notice how we have an OnClickListener for our fab,…which starts on line 21.…Now let's say we want to show snackbars…in other parts of our application…with this same exact logic.…Well we can reuse this code…by means of an extension function.…So let's copy everything we have here…on lines 22 and 23,…so we can use it as a reference later.…
Now we're going to create a separate file,…which we call common extensions,…to hold everything for now.…And this is going to be a Kotlin file,…and as I mentioned we'll call it:…CommonExtensions.…So let's go a head and add our extension…to Android's view class.…So first we'll start by using the fun keyword.…It's going to be on the view class…and let's call it showSnackbar.…For now, let's not worry about the parameters.…
We're just going to paste the code that we had before…
- What Kotlin has to offer
- Working with lambdas
- Common Android extension functions
- Kotlin Android Extensions overview
- Making use of the Anko library
- Working with coroutines
- Nullability and collections
Skill Level Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
Developing AWS Lambda Functions with Kotlinwith Troy Miles1h 55m Intermediate
1. Kotlin Overview
2. Extension Functions and Properties
3. Incorporating Anko
4. Advanced Anko
5. Working with Collections
- 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.