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.

Using methods

Using methods

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

Start my 1-month free trial

Using methods

- [Instructor] In preparation for making our calculator, let's create a simple method that adds two numbers together. We'll start by going to our activity main file, selecting that hello world text view, and then giving it an ID. I'll call this textView with a capital V, and then press Return or Enter to commit the change, and head back over to our Kotlin file. From here, right below onCreate, I'm going to go down a few lines, so below that closed curly brace, but above this closed curly brace, and I'm going to create a method called addNumbers. So fun, space, addNumbers, capital N, some parentheses, an open curly brace, and when you type that, Android Studio automatically adds a closed curly brace, and then just press Return, and then your cursor goes between the two curly braces. Now inside of this code, we're going to write the body of the addNumbers method. So, we'll define a value, we'll call this num1, set it equal to a certain number, so just pick a number, type it in, 15…

Contents