‫Hello, developers, and welcome back.
‫In this video, we'll learn how to create this amazing application, the Greetings app.
‫This app will ask the user to enter his name, for example, Jack.
‫And when the user clicks on the say hello button, a toast message containing his name.
‫Say, Welcome Jack to our application.
‫I'll change the name of the user to David, Click say hello.
‫Welcome David, to our app.
‫I think you are excited to create this amazing app.
‫Let's jump into Android studio and start building this application.
‫Now let's create this application.
‫Open Android Studio Select New project, Select Empty Views Activity.
‫Select this not this.
‫Select this option.
‫Next name the Application Greetings app, the package, whatever you want and select the language Java
‫Click Finish.
‫And wait for Gradle to sync the project.
‫The first step in creating the application is to design the layout.
‫Let's move to activity.
‫Underscore main, remove this text view and start designing our layout.
‫I'll start with the edit text.
‫This edit text will get the data from the user.
‫So edit text is a user interface element that allows users to input text.
‫It represents a single line or multi-line text box where users can enter text such as their name, password
‫or any other information.
‫In our case, we need to get his name.
‫So Edit text is typically used to capture user input and can be customized with various attributes like
‫hint, text, text, color, background and so on.
‫The width would be matchparent, the height would be wrapcontent and you can see the edit text appears
‫here.
‫Android id don't miss to add the id edit text.
‫Then I'll add a hint.
‫You can see the hint appears here.
‫I'll drag and drop this edit text in the middle and.
‫Inferred constraints till now.
‫Don't be confused about Constraintlayout.
‫Just follow me.
‫Later on I'll talk about Constraintlayout in the deep and in details.
‫I need a button to trigger the action to trigger the message, the showing of message.
‫The display of the message.
‫So this button will be wrap content.
‫Wrap content ID would be equal to BTN and click or the text.
‫Say hello.
‫Then I'll drag and drop this button here under this this edit text and click on Insert Constraints button.
‫Then I'll create a text view which is a user interface element used for displaying text on the screen
‫text view, and this text view will act as a title in this application wrap content wrap content and
‫the ID would be title and the text would be welcome to greeting.
‫App and don't miss to add this closing tag, the forward slash and this greater sign.
‫This greeting app text here I'll infer constraints and then I'll add another attribute for this text
‫view.
‫The text size, which is 28 SP Now I'll copy this image.
‫I'll go to the drawable folder.
‫Paste it here.
‫Click okay and make sure that it is not a capital letter or starts with numbers.
‫This is a background and image for the background of this layout.
‫Here I will not use image view to display the image.
‫I'll use the image as an attribute, a background attribute for the constraint layout.
‫A layout refers to the visual structure and arrangement of user interface elements in Android application.
‫It defines how different UI components such as text views, buttons, image views, edit, text are
‫organized and displayed on the screen.
‫Later on in the next section, we'll talk about the layouts in details.
‫But in this application, just for making it a professional application, it looks beautiful.
‫I'll add an attribute Android background to this constraint layout and add drawable and use the background
‫for us.
‫Now let's move to the main activity and start defining our widgets.
‫You can define and initialize the widgets here, or you can simply write here the outside oncreate method
‫if you need to use it globally.
‫Edit, text, edit, text and the button my button, you can name it whatever you want.
‫The reference Alt+ Enter to create to import the button class.
‫So if you see we imported the button and the edit text from Android widget package text view title.
‫Now let's initialize them in the Oncreate method and in the Oncreate method all the widgets must be
‫initialized.
‫Edit Text equal Find the view by ID or ID or the ID of the edit.
‫Text is.
‫Edit text button my button equal.
‫Find the view by ID or.id dot BTN and the title will find view by id r, dot id dot title.
‫Then I need to get the data from the edit text and display them when the user press the button.
‫So my button dot set on click Listener.
‫Do you remember the listener new view on click Listener?
‫Or you can use Lambda expression but now use this old fashioned way.
‫And later on when we talk about Lambda expression, I'll show you how to remove this on click.
‫I need to get the data that it is entered by the edit by the user inside the edit text.
‫So I'll store them into a string called input input name equal to edit text dot get text.
‫This is the method that we need to use in order to get the input from the edit text Dot toString.
‫Then I need to display this input name into a toast message.
‫Toast is a small pop up message that appears temporarily on the screen to display brief information
‫on notification to the user.
‫We start by toast, click enter and you can see dot make text.
‫This is the method specific for the the the toast.
‫And here the message that I need to display.
‫Welcome.
‫And here I'll use the input name input name variable that's entered by the user.
‫So welcome, Jack.
‫Welcome, David.
‫Welcome.
‫Hamad Welcome.
‫Whatever the user is, welcome plus to our app, Save the Project and then click Run.
‫And here we go.
‫This is our application.
‫Welcome to Greetings app text.
‫This is the edit text.
‫Enter your name.
‫If I click on it, it will display for me the keyboard.
‫I'll enter David, then click on Say Hello Button and you can see the message.
‫Welcome David to our app.
‫You can see it's a short message.
‫I can edit the length of this toast.
‫I change length from short to long and run it again.
‫Enter the name, then click on it.
‫You can see the message.
‫Welcome David to our app will display if I change the user to Jack.
‫Say hello.
‫Welcome Jack to our app.
‫Congratulations guys.
‫We succeeded in creating this amazing application that will learn how to use the edit text, how to
‫use the button and how to display text and images in Android.