Building very first Android App.

 The best way to learn something is by actually doing it. So in this post, we will create a very basic android application using Android Studio in Java. 

We will be creating a simple Coffee Cup ordering app . In this, we will handling button click events and toast messages.

Toast message - A toast message is a simple message / feedback to the user about an operation in a small popup .It fills only the required amount of space for the message to be displayed and automatically disappears after timeout.

Now, once you create your Android Project, in the activity_main.xml file, add an ImageView and add a coffee cup image as the source image to it. Then add 2 buttons; one to increment the coffee cups and another to decrement them. Also, add a TextView that displays the total number of coffee cups(Initially set to 0). And finally, add a Button to display the toast message. Follow the below code :


Next, in the MainActivity.java file, initialize the views(3 Buttons and 1 TextView), and set ClickListeners to the three buttons. Declare a count integer that will hold the count of coffee cups. When the increment button is clicked, the count will increment by 1 and likewise, when the decrement button is clicked, the count will decrement by 1. The third button will display a toast message with the count of coffee cups . If the count is less than 0, we will display the appropriate message. Follow the below code :


Output : 



And that is it !!! You have successfully created your very first Android App .


Comments

Popular posts from this blog

How to play Audio on Button Click in app | Android App Development | Java

Custom SeekBar in Android Studio .

How to implement simple Pie Chart in app | Android Studio | Java | Android App Development