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 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;
@Override
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 () {
@Override
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 () {
@Override
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 () {
@Override
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 messageReset 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 () {
@Override
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
Related articles
- i want to make a reset button in java
- i want to make sure that the button to change the color is installed normally in javafx
- i want to add contextmenu to button with javafx
- java - unable to launch emulator in android studio
- java - unable to create eclipse dynamic web project
- unable to install java library lombok
- java - i want to change the screen when clicking a button in android studio
- java - i want to change the text of the answer button depending on the problem
- java - unable to draw class diagram on amateursuml in eclipse
- java - i don't respond when i press a button
- java - i want to change the color when i press the like button and keep the color changed
- i want to build an android application from ren'py launcher, but i am unable to proceed with an error (java compilation error)
- java - i want to display the toast by clicking the button
- about java button creation
- i want to implement a java button action
- java - i want to create a radio button branch with the equals method
- [java] how should the target of the delete button duplicated with be specified?
- java - cannot define listener for button with inflated layout
- java - the value specified by select button is not registered in db
- about reset button for javascript roulette task
- java - i want to set multiple items in the database, but i get an error that the number of arguments does not match
- java - i want to fix an error in android studio
- java - activity name and layout name cannot be specified when creating a project in android studio
- java - how to access the onclick method
- java - the value transferred by putextra and obtained by getstringextra cannot be used in the if statement
- java - regarding the compatibility between system overlay and recyclerview
- java - i can't implement admob rewards, so please tell me how to implement it
- java - i want to change the button color in android studio
- java - i want to change the flip animation image with a second click
- java - i don't know how to get the scroll position of a modal window in android studio webview
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.