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.
Connect a button to a method
From the course: Programming for Non-Programmers: Android & Kotlin
Connect a button to a method
- [Instructor] Almost all the methods in our calculator application are going to be connected to buttons. In other words, they're going to be triggered when a button is pressed rather than called in code. And again that applies to most, but not all of the methods in our code. So let's take a look at how to apply a method to a button. So our goal is when we press on a button that a method will be called. So I'm going to head over to my layout which is activitymain.xml, and I'm going to click and drag a button onto the screen. You can get a button from the Palette window. That's on the left side at the top. So on the left edge, we have different categories of user interface objects. I'm just going to choose All at the very top and then you should see button at the top of that list on the right side of the window. We can drag a button onto the screen below the text view that already exists in the layout. With the button selected, you can see the black squares on the corners of the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.