我是一個初學者,開始設計一個簡單的應用程序來跟蹤高爾夫分數。我花了一些時間試圖找出如何向用戶提供通知,他們無法在分數文本框下輸入字母。我曾嘗試使用包含整個字母表的數組,但尚未能使其工作。我目前正在嘗試使用InputFilter,但我沒有取得任何成功;應用程序在輸入信件時會崩潰。如何在EditText中輸入字母時的敬酒
EditText input1 = (EditText)findViewById(R.id.scorePrompt);
TextView output1 = (TextView)findViewById(R.id.textTotal);
String blankCheck = input1.getText().toString(); //CHANGE INPUT IN scorePrompt TO STRING
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (Character.isLetter(source.charAt(i))) { // Accept only letter & digits ; otherwise just return
Toast.makeText(getApplicationContext(),"NO LETTERS",Toast.LENGTH_SHORT).show();
return "";
}
}
return null;
}
};
我懷疑這是因爲我沒有直接將Inputfilter連接到我的blankCheck,但我不確定。任何幫助表示讚賞!
看到https://stackoverflow.com/questions/8543449/how-to-use-the-textwatcher-class-in-android – TWL
請解釋你想要什麼? –
[可惜MyApp已停止。我怎樣才能解決這個問題?](https://stackoverflow.com/questions/23353173/uncomfort-myapp-has-stopped-how-can-i-solve-this) –