Create OptionsMenu using an XML menu

The options menu is the primary collection of menu items for an activity. The menu items are displayed on the ActionBar. Step 1: In res/drawable/ directory add icons to be used in OptionsMenu. Take for example ic_add_white, ic_settings_white_24dp, and ic_info_outline_white. Step 2: Firstly, create the menu in xml. Open res/menu/ directory and create a new file menu_main.xml. … Read more

Display Toast messages at different positions

We can apply Gravity to the toast message to display it at various positions on the screen. Below are codes provided for displaying a Toast message at TOP, BOTTOM, RIGHT, LEFT, CENTER, TOP LEFT, and BOTTOM RIGHT positions. The method used for displaying Toast at different positions is .setGravity(int gravity, int xOffset, int yOffset).

Android TimePickerDialog

Here we will create a simple app which displays a TimePickerDialog on clicking an ImageView and displays the selected Time in a TextView. Step 1: Create a new project with name ‘Time Picker’ and package name com.myexample.appcompat.timepicker. Fill the forms and click “Finish” button. Step 2: In app level build.gradle add following dependencies: Step 3: In drawable folder add … Read more

Android DatePickerDialog

Here we will create a simple app which displays a DatePickerDialog on clicking an ImageView and displays the selected date in a TextView. Step 1: Create a new project with name ‘Date Picker’ and package name com.myexample.appcompat.picker. Fill the forms and click “Finish” button. Step 2: In app level build.gradle add following dependencies: Step 3: In drawable folder add … Read more

Create BMI Calculator App

Here we will create a simple app which calculates the Body Mass Index of an individual using his weight and height. Step 1: Create a new project with name ‘BMI Calculator’ and package name com.myexample.appcompat.bmi. Fill the forms and click “Finish” button. Step 2: In app level build.gradle add following dependencies: Step 3: Open res -> layout -> xml (or) … Read more

Age Calculator using DatePickerDialog

Here we will create a simple app which calculates the Age of an individual whose date of birth is provided. This app will use a DatePickerDialog for selecting the date of birth. Step 1: Create a new project with name ‘Age Calculator’ and package name com.myexample.appcompat.age. Fill the forms and click “Finish” button. Step 2: In app level … Read more

Gestational Age Calculator using DatePickerDialog

Here we will create a simple app which calculates the Gestational Age of a fetus during pregnancy, using the date of Last Menstrual Period(LMP). This app will use a DatePickerDialog for selecting the LMP. Step 1: Create a new project with name ‘Gestational Age Calculator’ and package name com.myexample.appcompat.gestation. Fill the forms and click “Finish” button. Step … Read more

AutoCompleteTextView Example

An AutoCompleteTextView is a View that is similar to EditText, except that it shows a list of completion suggestions automatically while the user is typing. Here we will create a simple app which displays an AutoCompleteTextView in which we can type the name of any international airport in India. The app will display the list … Read more

Android Spinner Example

Spinners provide a quick way to select one value from a list of values. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. Here we will create a simple app which displays … Read more