August 2017
Intermediate to advanced
440 pages
10h
English
Using default named arguments and lambda expressions can be really useful in Android. Let's look at some practical Android examples. Let's suppose we have a function that downloads elements and shows them to the user. We will add a few parameters:
fun getAndFillList(onStart: () -> Unit = {}, onFinish: () -> Unit = {}){
// code
}
Then, we can show and hide the loading spinner in onStart and onFinish:
getAndFillList(
onStart = { view.loadingProgress = true } ,
onFinish = { view.loadingProgress = false }
)
If we start it from swipeRefresh, then we just need to hide it ...
Read now
Unlock full access