This course begins by downloading Android studio - make sure you watch the appropriate video depending on whether you're on Mac or Windows. Then, we'll take a tour off the Android Studio interface and see how apps are put together. You'll learn about text views, buttons, and images to build a user interface for our app, and we'll also write some code to make our apps interactive.
Then we'll move onto a practical project in which we make a temperature converter app, which converts temperatures from Fahrenheit to Celsius. You'll be able to follow, building the app, and then running it on your system.
Intended Audience
This course is intended for beginners to Android app development or anyone who wants to master coding in Kotlin.
Prerequisites
Since this is a beginner level course, there are no requirements, but any previous experience with coding would be beneficial.
Hello, and welcome back. In this video, we'll display a little message to the user once they perform an action, like tap the button over here. So, let's take our login demo app, which we created or any other app that you have open, which has a button, and when you click on the button, you want it to display a message back to the user. So far, we've only seen how to log a message or any kind of other interaction to the logs when we click something or do something over here, but now we'll take it a step further and actually interact back with the user.
And this is actually pretty easy using what's known as a Toast. So, pull up a new browser window, and type in Toast Android and you see a whole bunch of links pop up from developer.android.com. And I can go to this first one, Toasts overview, and they have some information about Toasts and how to use them. So, here is some sample code. What I'm going to do, is copy from here right after this "val toast," I'm going to copy this part right here and then Command C, and go back to our function. Right here back to my clickFunction, I'm going to paste it at the bottom here. All right.
Okay, so there are a few things going on here. First is, Toast right here. We have to import this package. Right now android doesn't know what's going on. So, I'm going to do 'option Shift Enter,' and this will import the Toast package right here, android.widget.Toast. And then, over here, the first one is the applicationContext. Here, I'm going to get rid of this. What we'll say is this,
okay? So, basically the application that we are running, and we'll find out more about what this is when we look a little deeper into object oriented programming. But for now, just think of the instance of this logging demo application that's running. So this. The next thing is text over here. So, what is the text you want to display? So, I'll say "Hello Mashrur" over here and then duration, you have to specify the duration. For that, we're going to say "Toast." So, T. and then you see LENGTH_SHORT, LENGTH_LONG. We'll say, LENGTH_SHORT right here. And then, the last part, toast.show from the example, this was in a separate line because they were using this variable toast, we're not using that, we're simply referencing this directly.
Therefore in order to display this, what we have to do is add the .show to the end right here, .show() and then get rid of this line right here. So, let's see what happens when we run this. I'm going to run app, pull up my emulator. Process app is running. Do you want to terminate? Yap, terminate the older one. So, the new one pops up. Alright. There we go. It's up. So, if I click on this sign in our Register button, check it out, there's the message that pops up, "Hello Mashrur". If I do it again, you see it pops up again. Now if you type something here, let's say, Mashrur and then some password, and the soft-touch keyboard shows up and if I click on the sign the register button you see it's showing up on top of this virtual soft-touch keyboard. So, what you can do here is click on this checkmark to get rid of it, then click on this and then it pops up.
The other option is, if it pops up at the bottom here, you see this keyboard, if you click on this, you see "Choose input method" and you can show the virtual keyboard or you can also get rid of it, right? So, that's up to you for now. And in general, I just click this checkmark to get rid of it. You can also do this programmatically, but it's a bit more complicated than we are ready for right now so I won't get into that. All right, great. So, this functionality is working and we can send messages to the user but our message is hardcoded right now. You see this text portion. "Hello Mashrur" we hardcoded it. In the next video, we'll see how we can customize this message based on the data the user is entering in the text field. Let's say we want to say Hello and then the email address right here. So, that's what we're going to tackle next. Hope you're excited. And I'll see you in the next video.
Mashrur is a full-time programming instructor specializing in programming fundamentals, web application development, machine learning and cyber security. He has been a technology professional for over a decade and has degrees in Computer Science and Economics. His niche is building comprehensive career focused technology courses for students entering new, complex, and challenging fields in today's technology space.