john ruan john ruan - 2 months ago 6x
Android Question

I have a button that doesnt respond. After I turn off screen and turn it back on it responds. other button works fine. help pls

this is my main

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

import static*;

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
playeronestack = (TextView) findViewById(;
playertwostack = (TextView) findViewById(;
playeronecheckbutton = (Button) findViewById(;
playertwocheckbutton = (Button) findViewById(;
playeronebetbutton = (Button) findViewById(;
playertwobetbutton = (Button) findViewById(;
playeronefoldbutton = (Button) findViewById(;
playertwobutton = (Button) findViewById(;
playeronebettext = (EditText) findViewById(;
playertwobettext = (EditText) findViewById(;
playeronefirstcard = (ImageView) findViewById(;
playertwofirstcard = (ImageView) findViewById(;
playeronesecondcard = (ImageView) findViewById(;
playertwosecondcard = (ImageView) findViewById(;
firstflopcard = (ImageView) findViewById(;
secondflopcard = (ImageView) findViewById(;
thirdflopcard = (ImageView) findViewById(;
fourthflopcard = (ImageView) findViewById(;
fifthflopcard = (ImageView) findViewById(;
dealerbuttonone = (ImageView) findViewById(;
dealerbuttontwo = (ImageView) findViewById(;
pottext = (TextView) findViewById(;
startbutton = (TextView) findViewById(;

if(turn == 2){
if(turn == 7){
startbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
turn = 1;
if(turn == 1) {;


I know its sloppy I just started ;)
turn starts out at 7 and when I hit it it doesn't respond. But after I close the screen and open it again, it responds. Its so weird ;-;. any help?
Also I have all the variables in a different class. Turn 1 is supposed to deal the cards and at the start of turn 2 it displays the cards. In the it sets turn to turn 2. It works but you have to close the screen and turn it on for it to proceed



Your current code will only run once, as the method is only called once in the whole lifecycle of the app, onCreate. What you need to do is the following:

  1. Where you've defined your button in XML, add this code:


  2. Create the method in the class with the following syntax:

    public void YOUR_METHOD_NAME (View v) {
    if (turn == 1) {
    else if (turn == 2) {
    else if (turn == 7) {
    /*Add a fallback clause in case none of the     conditions are met as a safeguard*/
  3. Reformat your code to make it more readable - delegate different code to different functions!!

EDIT replace everything in the method you created with only the following code

turn = 1;