Android execute function after pressing quot;Enterquot; for EditText(Android按“Enter后执行功能对于 EditText)
问题描述
我一直在关注官方的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android按“Enter"后执行功能对于 EditText


- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01