问题的简短版本:如何在Android中的软输入/键盘上捕获长按事件?
长版:在Android应用程序中,我们有一个多行EditText,我们希望有这样的行为:1.默认情况下,它显示一个DONE按钮,通过点击它,软输入/键盘将被关闭.2.如果用户长按DONE按钮,其行为将更改为ENTER按钮,EditText中将有一个新行.
对于需求#1,我在这里使用了解决方案:https://stackoverflow.com/a/12570003/4225326
对于需求#2,我遇到的阻塞问题是,如何捕获长按事件.我设置了onEditorActionListener,但捕获的事件为null:http://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html 我搜索了文档,长按相关的方法是针对硬键盘:http:http: //developer.android.com/reference/android/view/View.html#onKeyLongPress(int,android.view.KeyEvent),我找不到一个用于软输入/键盘.
感谢您查看此问题.
以下是我从Apple的"计时器编程主题"中看到的示例代码:
NSMethodSignature *methodSignature = [self
methodSignatureForSelector:@selector(invocationMethod:)];
NSInvocation *invocation = [NSInvocation
invocationWithMethodSignature:methodSignature];
[invocation setTarget:self];
[invocation setSelector:@selector(invocationMethod:)];
NSDate *startDate = [NSDate date];
[invocation setArgument:&startDate atIndex:2];
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我们必须指定invocationMethod
:一次在NSMethodSignature
中,然后第二次NSInvocation
的setSelector
.对我来说,这似乎是多余的,苹果设计有这样的理由吗?