In the continuing adventures of higher education and personal learning, I made a simple little guessing game for Android, as instructed by my online course for Android app development. It is a very basic game, where the user must guess the number Android is thinking of. You can download it here:

Android chooses a new number every time you open the app, so it has infinite replay value!

Here is the breakdown of the major components:






package com.alaskalinuxuser.guessthenumber;

import android.os.*;

import java.util.*;

import android.view.*;


import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.*;

public class MainActivity extends Activity 



    protected void onCreate(Bundle savedInstanceState)





Random appRandom = new Random();

int hidRandom = appRandom.nextInt(81) + 10;

public void takeGuess(View v)


EditText userGuess = (EditText) findViewById(;

Double uGuess = Double.parseDouble(userGuess.getText().toString());

if (uGuess hidRandom) {
Toast toast = Toast.makeText(getApplicationContext(), “Too high!”, Toast.LENGTH_SHORT);

toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);;
} else {
Toast toast = Toast.makeText(getApplicationContext(), “That’s right, you guessed it!”, Toast.LENGTH_SHORT);

toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);;



As you can see, there is not much to this app. I was pleased that I was able to put it together in about 15 minutes (Praise God!), and, while simple, it is somewhat fun, if you’re board!
Linux – keep it simple.

2 Replies to “​Android number guessing game!”

Leave a Reply

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