android - OnEditorActionListener 中的 requestFocus()
问题描述
下面是我为将焦点从一个编辑文本转移到另一个而编写的一段代码,但是我在这个实现中遇到的问题是,焦点移动到特定的编辑文本,然后突然移动到下一个编辑文本. 所以,我无法输入任何内容,因为焦点根本不在于特定的编辑文本..
//some code comes here
// gun_pistolNotes and gun_pistolModel are two diff. editText
......
......
gun_pistolNotes.setOnEditorActionListener(new OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView view,int actionId, KeyEvent event){
if(actionId == EditorInfo.IME_ACTION_UNSPECIFIED){
gun_pistolModel.requestFocus(); // moves to this edittext and suddenly moves to another editext
return true;
}
return false;
}
});
......
......
//some code comes here
任何帮助表示赞赏。
解决方案
如果你不需要实现任何相关的逻辑,你也可以直接在你的布局文件中实现,而不是通过程序来实现,使用android:nextFocusDown
如下所示的属性:
...
...
<EditText
android:id="@+id/gun_pistolNotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:nextFocusDown="@+id/gun_pistolModel" />
<EditText
android:id="@+id/gun_pistolModel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
...
...
推荐阅读
- django - Django在测试时没有创建测试数据库
- c - C - 读取文件并将文本放入具有动态内存分配的字符指针
- python - 在 Python 中带有返回值的 C# 回调
- java - Android : 如何跟踪键盘使用情况
- mongodb - 如何在 mongoDB 的两个不同集合中进行查询?(不使用 ORM)
- header - 如何在 Blazor 中订阅 onscroll 事件?
- delphi - Inno Setup 中的 WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo) 是什么意思?
- java - 如何在Java中读取多个具有相同名称的列
- sql-server - SQL Server - 带有 WHERE 子句的 UNION 在简单连接时非常慢
- mongodb - MongoDB 在一个排序阶段查询多个集合