activity_main.xml:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00ACC1" tools:context=".MainActivity"> </androidx.constraintlayout.widget.ConstraintLayout> MainActivity.java: package com.example.randomnumber; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.util.Random; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Random myRandom = new Random(); Button buttonGenerate = (Button)findViewById(R.id.generate); final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber); buttonGenerate.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub textGenerateNumber.setText(String.valueOf(myRandom.nextInt(100))); } }); } }