(App)How to Make Random Number Generator Android App – Droidblogger

The random number generator android app generates a random number in the given range i.e., shows a number that is inclusive of the beginning number and ending number.

To make this app we use two EditText components to take the beginning number and ending number respectively.One Button component to generate the random number and TextView to show the random number.Initially, we have to define the strings to show hints in the EditText components and text on Button component.
In this project, strings.xml file looks like this.res>values>strings.xml

Let’s create a layout for UI for the project. In this project, activity_main.xml is the layout file for UI. Two EditText components, one Button component, and two TextView components are defined in the layout. The code in the layout finally looks like below[irp posts=”53″ name=”How to Make Circle Button With Text and Icon in Android”]


In the default java file i.e., in MainActivity.java, define all the UI components as below.

setOnClickListener(this) is set to button for button click event. To set this, you must implement View.OnClickListener interface.In this OnClick(View View) method, instructions to generate random number are defined as below

We have a static method Number(int min,int max) of int typeit returns a random number. This method looks as below

Random is a class of util package. A Random object random is created to generate a random number. If the beginning number is greater than ending number then a toast will pop up showing “Ending Number must be greater”The total code in the MainActivity.java is as belowMainActivity.java

The Final look of the app will be as belowrandom number generatorDownload Source Code:

You May Also Like

About the Author: Sama Gyani

I am Computer Science Graduate. I turn my interests into posts here.

Leave a Reply

Your email address will not be published. Required fields are marked *