Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: How to wait for an input from an editText
    primarykey
    data
    text
    <p>I am having a problem with a hangman game that I made for android. I have made a version for the computer and used the code on the android version. I made all the necessary changes to print etc. The program on android just loops through everything until you lose. How can I make it wait for an input from an editText before continuing? Note:More code can be given if needed.</p> <pre><code> package com.aimobile.hangman; import java.util.Arrays; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity{ protected static char in; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //gui final EditText input = (EditText) findViewById(R.id.input); EditText hang = (EditText) findViewById(R.id.hang); hang.setEnabled(false); Button guess = (Button) findViewById(R.id.guess); //Begin Hangman int nchar = 5; char[] word; word = new char[nchar]; word[0] = 'h'; word[1] = 'e'; word[2] = 'l'; word[3] = 'l'; word[4] = 'o'; char[] arinput; arinput = new char[nchar]; arinput[0] = '*'; arinput[1] = '*'; arinput[2] = '*'; arinput[3] = '*'; arinput[4] = '*'; int lives = 5; while (lives&gt;0){ hang.append("Enter leter:"); guess.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainActivity.in = input.getText().charAt(0); } }); boolean wrong=true; for(int k=0; k&lt;= nchar-1; k++){ if(arinput[k]==in){ hang.append("You already have this"); wrong=false; } else if(word[k]==in){ arinput[k]=in; wrong=false; } } hang.append(Arrays.toString(arinput)); boolean finish=true; for(int k=0; k&lt;= nchar-1; k++){ if(word[k]!=arinput[k]){ finish=false; } } if(finish){ hang.append("You win"); System.exit(0); } if(wrong){ lives--; hang.append("You have "+ lives +" lives left"); } } hang.append("You lose"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload