我正在尝试添加键盘侦听器...
txta1cresult.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v,int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE){
calculate();
}
return false;
}
});
但是,我收到以下编译器错误...
/home/jocala/hba1c/src/com/android/hba1c.java:82: cannot find symbol
symbol : class OnEditorActionListener
location: class com.jocala.hba1c.hba1c
txta1cresult.setOnEditorActionListener(new OnEditorActionListener() {
这是我的EditText
...
<EditText
android:id="@+id/txta1cresult"
android:inputType="numberDecimal"
android:layout_width="80px"
android:maxLength="5"
android:layout_height="40px"
android:textSize="18sp"
android:layout_x="200px"
android:layout_y="32px"
>
</EditText>
我需要导入和以外的东西EditText
吗TextView
?这里还有什么问题吗?
[javac] Compiling 3 source files to /home/jeff/hba1c/bin/classes
[javac] /home/jeff/hba1c/src/com/android/hba1c.java:83: cannot find symbol
[javac] symbol: class KeyEvent
[javac] public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
[javac] ^
[javac] /home/jeff/hba1c/src/com/android/hba1c.java:84: cannot find symbol
[javac] symbol: variable EditorInfo
[javac] if(actionId==EditorInfo.IME_ACTION_DONE){
[javac] ^
[javac] 2 errors
修复导入后剩余 2 个错误:
[javac] Compiling 2 source files to /home/jeff/hba1c/bin/classes
[javac] /home/jeff/hba1c/src/com/android/hba1c.java:161: cannot find symbol
[javac] symbol: class KeyEvent
[javac] public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
[javac] ^
[javac] /home/jeff/hba1c/src/com/android/hba1c.java:162: cannot find symbol
[javac] symbol: variable EditorInfo
[javac] if(actionId==EditorInfo.IME_ACTION_DONE){
[javac] ^
[javac] 2 errors
它似乎扼杀了这段代码:
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE){
calculate();
}
最后修复:
导入android.view.KeyEvent;导入android.view.inputmethod.EditorInfo;
谢谢!