onOkInSoftKeyboard-6ren">
gpt4 book ai didi

android - 在数据绑定(bind)中使用键盘上的完成按钮

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:44 25 4
gpt4 key购买 nike

我正在尝试使用软键盘的完成按钮通过数据绑定(bind)激活方法。就像点击一样。有办法吗?

例子:

<EditText               
android:id="@+id/preSignUpPg2EnterPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
onOkInSoftKeyboard="@{(v) -> viewModel.someMethod()}"
/>

onOkInSoftKeyboard 不存在...是否有创建此行为的方法?

谢谢!

最佳答案

我不会声称自己是 onEditorAction() 或软键盘方面的专家。也就是说,假设您使用 Firoz Memon 建议的堆栈溢出问题的解决方案,您可以实现它。即使有其他更好的解决方案,这也可以让您了解如何添加自己的事件处理程序。

您需要一个采用某种处理程序的绑定(bind)适配器。假设您有一个像这样的空监听器:

public class OnOkInSoftKeyboardListener {
void onOkInSoftKeyboard();
}

然后你需要一个 BindingAdapter:

@BindingAdapter("onOkInSoftKeyboard") // I like it to match the listener method name
public static void setOnOkInSoftKeyboardListener(TextView view,
final OnOkInSoftKeyboardListener listener) {
if (listener == null) {
view.setOnEditorActionListener(null);
} else {
view.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public void onEditorAction(TextView v, int actionId, KeyEvent event) {
// ... solution to receiving event
if (somethingOrOther) {
listener.onOkInSoftKeyboard();
}
}
});
}
}

关于android - 在数据绑定(bind)中使用键盘上的完成按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45288013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com