Android App Development | Beginner Course | Lecture#12 | Hive Learners
𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼
Hello, dear community members of Hive Learners, I hope you all are well. Today we will step up in our java programming. We will use edit text views and get a text from there and show it on the screen message. In this way, we will learn how to get the text from the edit text when we make the signing page for the app with the database.
GitHub Link
Use this GitHub project to clone into your directory. It will always get updated in the next lecture. So that you will never miss the latest code. Happy Coding!.
What Should I Learn
- How to center a layout or widget.
- How to get a text from Edittext.
- How to concatenate two strings.
Assignment
- Create your own Sign-in screen design.
- Show the password and Email on the Sign-in button click.
Procedure
I edit my design activity code and turn it into a sign-in page. It contains a Linearlayout which contains a TextVuew, two Textinput and Edittext, and OneSignin Material Button with Icon. I center the TextView by using this line in the TextView tag.
android:layout_gravity="center"
Then I set the id for the edittext email and password. This id will use to link this edittext to our JAVA code. Also, set an id for the signing button.
Now open the MainActivity.java file and declare the variables and attach the id with the variables.
now I declare two string
variables on the on-click listener to store the email and password get from the edittext fields that are entered by the user. We use the getText() method to get the text from the Input Fields like edittext.
String email = email_et.getText().toString();
String pass = pass_et.getText().toString();
Now concatenate the two strings to a third String variable by using the +
sign, I also add space by using a String in the concatenation. You can use double quotation marks or single quotation marks for a string.
String result = email + ' ' + pass;
Now we add this result
variable in the Toast message like this and run the app.
On the emulator enter a random email and password and click in Sign In button. It will display the email with a space and then the password to your emulator screen. I hope you enjoy today's lecture, See you tomorrow.