我有4个编辑文本;oct1
,oct2
,oct3
,oct4
。这些编辑文本是numberDecimal
类型。我最初关注oct1
。我需要它,所以当用户按.
(NUMPAD点)时,它将 not 输入.
oct the Oct,清除重点并专注于下一个编辑文本。
这个应该很容易,但对我来说令人沮丧。这就是我尝试的。
覆盖onKeyDown
。这甚至不会产生日志。
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_NUMPAD_DOT){
oct3.clearFocus();
oct4.requestFocus();
return true;
}
Log.d("KeyCode", String.valueOf(keyCode));
Log.d("event", String.valueOf(event));
return false;
}
然后。我有许多不同的变体。我已经能够切换焦点,但不能删除.
。
oct3.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(count > 0){
if(s.charAt(s.length()-1) == ".".charAt(0)){
Log.d("Sequence", "Noticed a "."");
isPeriod = true;
} else {
Log.d("Sequence", "Noticed a ""+s+""");
}
}
}
@Override
public void afterTextChanged(Editable s) {
if(isPeriod){
s.delete(s.length() -1, s.length() -1);
oct3.clearFocus();
isPeriod = false;
oct4.requestFocus();
}
}
});
尝试在onTextChanged
中设置它:
listener = (new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(count > 0){
if(s.charAt(s.length()-1) == '.'){
Log.d("Sequence", "Noticed a "."");
CharSequence text = s.subSequence(0, s.length()-1);
Log.d("VIEW CLICKED:", String.valueOf(getCurrentFocus()));
setTextAndAdvance(getCurrentFocus(), text);
} else {
Log.d("Sequence", "Noticed a ""+s+""");
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});