我在1月份將我的舊Hangman java遊戲移植到我的編程決賽中的android。我已經獲得了大部分工作,但是我發現我沒有對無效字符進行任何檢查。無效字符基本上都是小寫字母。我一直在考慮手動輸入所有有效的字符到數組中,並檢查每個輸入。有沒有更簡單的方法來做到這一點?確保EditText只返回單個小寫字母
下面是從相應的EditText捕捉輸入代碼:再次
final EditText guessedLetter = (EditText) findViewById(R.id.LetterInput);
final Button enterGuess = (Button) findViewById(R.id.GuessButton);
enterGuess.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String guess = guessedLetter.getText().toString(); //Save text to a string
guessedLetter.setText(""); //Clear EditText after input has been saved to a String
editor.putString(GAME_LOGIC_GUESS, guess);
editor.commit();
Log.i(GAME_DEBUG, "Guess: " + guess + " parsed to guess()");
guess();
checkWin();
updateDisplay();
}
}});
謝謝!
我不知道,我應該用這個。你能指定一下嗎? – SQDK 2010-12-16 16:58:06