gpt4 book ai didi

android EditText imeOptions OnClick

转载 作者:太空宇宙 更新时间:2023-11-03 12:33:19 28 4
gpt4 key购买 nike

有了按钮就很简单了

<Button 
android:blablabla="blabla"
...
android:onClick="doSomething" />

这将执行 doSomething(View) 函数。

我们怎样才能用 EditText 模仿这个?我已经读到过这个,我读到大多数人使用 imeOptions(这似乎仍然是必要的),然后在该 EditText 对象上实现 actionListener。

这是我迷路了。有没有一种方法可以像我们使用按钮那样从键盘向 onClick 函数实现“完成”操作(或发送或...),或者我们是否需要显式地实现监听器?

问候!

最佳答案

当您按下软键盘上的 Done 键时,下面的代码将执行一些操作。

editText.setOnEditorActionListener(new OnEditorActionListener() {        
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE){
//do your actions here that you like to perform when done is pressed
//Its advised to check for empty edit text and other related
//conditions before preforming required actions
}
return false;
}
});

希望对您有所帮助!!

关于android EditText imeOptions OnClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27051351/

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