问题描述
我一直在关注官方的 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(){})
并且还用错误在 OnKeyListener
下划线:
And also underlines OnKeyListener
with the error:
类型new DialogInterface.OnKeyListener(){}必须实现继承的抽象方法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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!