My “Hello World” Android App
I have been learning Java, on my own, for the past few days. I reckoned that it would be a fun project to make a simple Android app and to get familiar with the Android Studio environment.
The objective of my app would be:
- Have two text rows to fill in the first and last names
- The user can click a REGISTER button
- Once the button is clicked, two lower text columns would display the aforementioned text data
As one can note, this would be an extremely novice app devoid of any complications. In other words, an ideal Hello World app for a beginner in the world of Android.
Project Structure
When starting a project in Android Studio, one is first confronted with the option of adding an Activity to Mobile. I went with the Empty Activity choice. This alternative gives the developer with empty activity_main.xml and MainActivity.java files for the app along with boilerplate code for building the app (gradle scripts). The xml file is for UI while the java file would contain the business logic.
Project Code
I began with designing the User Interface. In the design mode for the xml file, I could add text fields and a button for the app. The first two text fields were of the EditText type (where the user would enter the details) while the later two were of the TextView type. I added a button that and named it as REGISTER. I constrained the location for each of these fields.
Next, I added an onClick option for the REGISTER button in my xml file, like so:
The business logic was quite straightforward. I added the following lines to my Java file:
Final Product
So, here’s how the app looks. The user can fill in the names in the top two text field:
Once, the user hits the register button, the names get dispayed below:
Well, that was fun!