Build an Android App to Check a Year is Leap Year or Not
In this article, we will learn how to make an App to check a year is a leap year or not. Before that, we need to have an idea of what is a leap year? If a year is:
- Multiple of 400
- multiple of 4 and not multiple of 100
Then the year is a leap year.
- if the year is divisible by 400 then it is a leap year.
- else if the year is divisible by 100 then it is not a leap year.
- else if the year is divisible by 4 then it is a leap year.
- else it is not a leap year.
Now we will make an App for that. So, if we find a year is leap or not we will display a Toast.
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Step 3: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail. Here we will bind the views and write the logic of the app.