0
我對Android開發很新穎。我試圖在鍵入EditText
元素時檢測空格,然後立即向EditText
元素添加換行符。基本上,試圖用「輸入」擊鍵代替空格擊鍵。我越來越接近了,因爲我在輸入到EditText元素時已經設法檢測到「空格」,但是在檢測到空格時,我正在將「enter」鍵事件分派到EditText
元素中。任何幫助將不勝感激。我覺得我正處在答案的尖端,我只需要在正確的方向稍微推動一下。(Android)向EditText發送「ENTER」鍵事件
public void addInputWordListener(){
inputWord.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
sStr = s.toString();
if(sStr.equals("")){
topView.setTextColor(Color.WHITE);
return;
}
if (sStr.endsWith(" ")){ //space found!
token = s.toString().trim();
if (token.equalsIgnoreCase(topView.getText().toString())){
inputWord.dispatchKeyEvent(KeyEvent.KEYCODE_ENTER); //doesnt work??
topView.setText(midView.getText());
midView.setText(botView.getText());
botView.setText(MainMenu.we.nextWord());
MainMenu.user.totalWords++;
}else{
topView.setTextColor(Color.RED);
MainMenu.user.totalWords++;
MainMenu.user.numErrors++;
}
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
}
你應該..:D – 2013-06-03 11:34:19