KeyCode_Enter 到 ListView 中的下一个 EditText
我有带有一些 EditText 的多行 ListView 。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_tail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<EditText
android:id="@+id/edit_cost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<EditText
android:id="@+id/edit_rest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
在EditText中,输入“Enter”键后,系统建立焦点如下:
[EditText] [EditText] [EditText]
↓ ↓ ↓
[EditText] [EditText] [EditText]
↓ ↓ ↓
[EditText] [EditText] [EditText]
↓ ↓ ↓
... ... ...
但我想:
[EditText] -> [EditText] -> [EditText] ->
-> [EditText] -> [EditText] -> [EditText] ->
-> [EditText] -> [EditText] -> [EditText]
如何解决这个问题?
I have multiline ListView with a few EditText.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_tail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<EditText
android:id="@+id/edit_cost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<EditText
android:id="@+id/edit_rest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
In EditText, after typing 'Enter' key, system establishes focus as follows:
[EditText] [EditText] [EditText]
↓ ↓ ↓
[EditText] [EditText] [EditText]
↓ ↓ ↓
[EditText] [EditText] [EditText]
↓ ↓ ↓
... ... ...
But I want:
[EditText] -> [EditText] -> [EditText] ->
-> [EditText] -> [EditText] -> [EditText] ->
-> [EditText] -> [EditText] -> [EditText]
How solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我只是在 EditTexts 中水平移动焦点时遇到了同样的问题。就我而言,我只有几个 EditText,因此我将
android:imeOptions="actionNext"
添加到每个 EditTexts xml,然后将 OnEditorActionListener 添加到每个 EditText。代码示例:这是解决该问题的相当不错的方法。
I just had the same problem of moving focus horizontally in EditTexts. In my case I just had a few EditTexts so I added
android:imeOptions="actionNext"
to each EditTexts xml and then added OnEditorActionListener to each EditText. Code sample:This is reasonably nice solution to the problem.
一种方法是手动将 ime 标题设置为“Next”(可以在 xml 或 Java 中完成),然后手动覆盖该活动的 onClick 侦听器并侦听按下的“next”键。然后,您可以在想要将焦点切换到的 EditText 上调用
requestFocus()
。老实说,虽然这会很麻烦,但我知道它会起作用。希望有更好的方法。One way would be to set the ime title to "Next" manually (can be done in xml or Java) and then manually override the onClick listener for that activity and listen for the "next" key being pressed. Then you could just call
requestFocus()
on the EditText that you are wanting to switch the focus to. Honestly though this would be quite a hassle but I know it would work. Hopefully theres a better way.要为 ListView 中的 EditText 提供从左到右、从上到下的聚焦,您可以使用以下 XML 选项:
它对我有用,希望对您有所帮助。
To provide focusing from left to right and from top to bottom for EditText in ListView, you can use following XML options:
It works for me and hope it helps you.