我想添加一個鍵盤監聽器...Android的數字鍵盤
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的; import android.view.inputmethod.EditorInfo;
謝謝!
請幫忙嗎?只是學習Java,如果這不明顯。只要按下軟鍵盤「完成」時即可執行操作。 – Jocala