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:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01