I'm creating a bingo app in AndroidStudio using Java.
It is an application that keeps a numerical value selected at random in the bingo application in the log, but the reset button cannot be implemented.

The log value doesn't disappear and I don't get any response when I press the reset button. If i have any questions about this problem, please tell me.

* All source code below is attached.
package com.example.renwhite.mybingo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;

import static com.example.renwhite.mybingo.R.id.ConstraintLayout;
import static com.example.renwhite.mybingo.R.id.current_number;
import static com.example.renwhite.mybingo.R.id.reset_max_number;

public class MainActivity extends AppCompatActivity {
// Maximum value
private int maxNumber = 75;
// Number history
private ArrayListhistory = new ArrayList<>();

// Maximum value field
private EditText maxNumberEditText;
// Maximum value setting button
private Button registerMaxNumberButton;
// button to get next number
private Button nextNumberButton;
// TextView to display the current number
private TextView currentNumberTextView;
// TextView to display history
private TextView historyTextView;
// Button to reset output log
private Button resetMaxNumber;

protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);

// Initialize view variables
maxNumberEditText = findViewById (R.id.max_number);
registerMaxNumberButton = findViewById (R.id.register_max_number);
nextNumberButton = findViewById (R.id.next_number);
currentNumberTextView = findViewById (R.id.current_number);
historyTextView = findViewById (R.id.history);
resetMaxNumber = findViewById (R.id.reset_max_number);

// Reset values ​​
final Button resetMaxNumber = findViewById (R.id.reset_max_number);
resetMaxNumber.setText ("Reset");
resetMaxNumber.setOnClickListener (new View. OnClickListener () {
public void onClick (View view) {
// Restore the output log to the initial value

Log.d ("MainActivity", "resetMaxNumber");


// Set the initial maximum value to EditText
maxNumberEditText.setText ("" + maxNumber);

// Update the maximum value
registerMaxNumberButton.setOnClickListener (new View.OnClickListener () {
public void onClick (View v) {
// take the input value as a string
String maxNumberString = maxNumberEditText.getText (). ToString ();
// Substitute after converting to int type
maxNumber = Integer.valueOf (maxNumberString);

Log.d ("MainActivity", "maxNumber:" + maxNumber);

// Update the displayed number
nextNumberButton.setOnClickListener (new View.OnClickListener () {
public void onClick (View v) {
onClickNextNumber ();

// What happens when nextNumberButton is tapped
private void onClickNextNumber () {
Log.d ("MainActivity", "onClickNextNumber");

// A random number considering maxNumber
int nextNumber = createRandomNumber ();// ①

// If the number is a duplicate, generate the number again
while (history.contains ("" + nextNumber)) (// ②
Log.d ("MainActivity", "Recreated because it was duplicated");
nextNumber = createRandomNumber ();// ③

// Convert nextNumber to string
String nextNumberStr = "" + nextNumber;// ④

// Display nextNumber on the screen
currentNumberTextView.setText (nextNumberStr);

// Leave history
history.add (nextNumberStr);

// Leave history
historyTextView.setText (history.toString ());

Log.d ("MainActivity", history.toString ());
// Generate a random number considering maxNumber
private int createRandomNumber () {
// Generate a numerical value between 0.0 and 74.0 (when the maximum value is the initial value)
double randomNumber = Math.random () * (maxNumber-1);
// Generate an integer value between 1 and 75 (when the maximum value is the initial value)
return (int) randomNumber + 1;



Error message
Reset button does not respond
Applicable source code
// Reset the number
        final Button resetMaxNumber = findViewById (R.id.reset_max_number);
        resetMaxNumber.setText ("Reset");
        resetMaxNumber.setOnClickListener (new View. OnClickListener () {
            public void onClick (View view) {
                // Restore the output log to the initial value
                Log.d ("MainActivity", "resetMaxNumber");

The bingo app was created using a reference book. I tried the code from among the ones with a numeric reset button.

Supplemental information (FW/tool version etc.)

Usage environment:
Android Studio 3.5.1

  • Answer # 1

    When the reset button is pressed, the only action is "output log", which is virtually nothing.
    It is necessary to return the text box where the history is written to the initial state or to return the maximum value to the initial value here.

    Rather, it's overwhelmingly easier for bingo machines to put numbers between 1 and 75 in a list or something and pick them randomly or shuffle them.