Android按“Enter"后执行功能对于 EditText

Android execute function after pressing quot;Enterquot; for EditText(Android按“Enter后执行功能对于 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)