問題描述
我一直在關注官方的 Android 教程,但不知何故遇到了 這個非常簡單的例子在為 EditText 按下Enter"后執行一個函數.
I have been following the official Android tutorials and somehow am having a problem with this very simple example to execute a function after pressing "Enter" for an EditText.
我明白我應該做什么,并且似乎所有設置都正確,但 Eclipse 抱怨這行:
I understand what I'm supposed to do and seem to have everything setup properly, but Eclipse is complaining with this line:
edittext.setOnKeyListener(new OnKeyListener() {
它在 setOnKeyListener
下標出錯誤:
View類型中的setOnKeyListener(View.OnKeyListener)方法不適用于參數(new DialogInterface.OnKeyListener(){})
The method setOnKeyListener(View.OnKeyListener) in the type View is not applicable for the arguments (new DialogInterface.OnKeyListener(){})
并且還用錯誤在 OnKeyListener
下劃線:
And also underlines OnKeyListener
with the error:
類型new DialogInterface.OnKeyListener(){}必須實現繼承的抽象方法DialogInterface.OnKeyListener.onKey(DialogInterface, int, KeyEvent)
The type new DialogInterface.OnKeyListener(){} must implement the inherited abstract method DialogInterface.OnKeyListener.onKey(DialogInterface, int, KeyEvent)
也許有人可以朝正確的方向射擊我?在我嘗試其他解決方案(我已經在 stackoverflow 上找到)之前,我真的很想弄清楚這一點,因為它讓我感到慌亂,作為官方教程,這么簡單的東西似乎不起作用.
Perhaps someone can shoot me in the right direction? Before I try other solutions (which I've already found on stackoverflow), I'd really like to figure this out because it has me flustered that something so simple to follow, as an official tutorial, doesn't seem work.
推薦答案
據我所知,您的導入似乎有誤.
From what I can see, It looks like you have the wrong import.
試試
edittext.setOnKeyListener(new View.OnKeyListener() {
或者添加這個導入
import android.view.View.OnKeyListener;
并刪除這個
import android.content.DialogInterface.OnKeyListener;
這篇關于Android按“Enter"后執行功能對于 EditText的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!