java - 安卓数字键盘

标签 java android compiler-errors

我正在尝试添加一个键盘监听器...

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>

我是否需要导入 EditTextTextView 以外的东西?这里还有什么问题吗?

 [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;

谢谢!

最佳答案

看起来您需要导入 TextView.OnEditorActionListener

相关的,注意KeyEvent参数。如果操作是由 Enter 键触发的(这听起来像您想要执行的操作),它将位于该参数中。您可以尝试这样做,而不是从 int 参数中收集它。

关于java - 安卓数字键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10520538/

相关文章:

java - 如何导入AndroidJUnit4

java - tomcat无法更新新编译的java文件

java - 模拟泊松等待时间

java - quartz scheduler.2.2x 创建 sql server 数据库模式?

android - android中的光测量

android - onStart() 是确定 "user has re-opened the app"的最佳位置是否正确?

Maven 构建的 Java 格式字符串错误

compiler-errors - VHDL - 分配默认值

c++ - 将值插入以不同方式排序的两个BST中

c - C-奇怪的问题-预期标识符