我正在尝试添加键盘监听器......
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();
}
最后修正:
import android.view.KeyEvent; import android.view.inputmethod.EditorInfo;
谢谢!
答案 0 :(得分:0)
您似乎需要导入TextView.OnEditorActionListener
相关地,请注意KeyEvent
参数。如果操作是由Enter键触发的(听起来像你想要做的那样),它将在该参数中。您可以尝试而不是从int
参数中收集它。
答案 1 :(得分:0)
您需要在代码中导入android.widget.TextView.OnEditorActionListener
。
或者,改变你的听众......
txta1cresult.setOnEditorActionListener(new OnEditorActionListener() {
到此......
txta1cresult.setOnEditorActionListener(new TextView.OnEditorActionListener() {
你得到的编译器错误基本上是说不知道OnEditorActionListener
是什么,所以你需要导入它。