From the course: Programming for Non-Programmers: Android & Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Boolean values

Boolean values

From the course: Programming for Non-Programmers: Android & Kotlin

Start my 1-month free trial

Boolean values

- [Instructor] So far the variables that we've created have been two different data types, numbers and strings. So now I want to introduce a third data type, now that we're talking about conditional statements. And that data type is called Boolean. And Boolean data types are either true or false, so they can only have two values. To create a Boolean variable, you just simply create a normal variable and set it equal to true or false. I'm going to create a property. So right underneath my class, not inside of a method, I'm going to create a Boolean property called isOn. I'll set that equal to false. So var isOn equals false. What we're going to use this for is a switch. We're going to create a button that when we click it, the text view says On. And when we click it again, it checks to see if the value of isOn is equal to true or false, and if it's true, it changes to false; and if it's false, it changes back to true. And that is also going to update the label. So basically, when you…

Contents