KeyCode_Enter 到 ListView 中的下一个 EditText

发布于 2024-12-23 04:28:55 字数 1398 浏览 6 评论 0原文

我有带有一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

池予 2024-12-30 04:28:55

我只是在 EditTexts 中水平移动焦点时遇到了同样的问题。就我而言,我只有几个 EditText,因此我将 android:imeOptions="actionNext" 添加到每个 EditTexts xml,然后将 OnEditorActionListener 添加到每个 EditText。代码示例:

_heightEdit.setOnEditorActionLister(getGotoNextListener(_weightEdit));
private OnEditorActionListener getGotoNextListener(final EditText next) {
        return new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_NEXT) {
                    next.requestFocus();
                    return true;
                }
                return false;
            }
        };
    }

这是解决该问题的相当不错的方法。

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:

_heightEdit.setOnEditorActionLister(getGotoNextListener(_weightEdit));
private OnEditorActionListener getGotoNextListener(final EditText next) {
        return new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_NEXT) {
                    next.requestFocus();
                    return true;
                }
                return false;
            }
        };
    }

This is reasonably nice solution to the problem.

凉栀 2024-12-30 04:28:55

一种方法是手动将 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.

む无字情书 2024-12-30 04:28:55

要为 ListView 中的 EditText 提供从左到右、从上到下的聚焦,您可以使用以下 XML 选项:

<?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_1"
        android:nextFocusRight="@+id/edit_2"
        android:imeOptions="actionNext"
        />

    <EditText
        android:id="@+id/edit_2"
        android:nextFocusRight="@+id/edit_3"
        android:imeOptions="actionNext"
        />

   <EditText
        android:id="@+id/edit_3"
        android:nextFocusRight="@+id/edit_4"
        android:imeOptions="actionNext"
        />

   <EditText
        android:id="@+id/edit_4"
        android:nextFocusDown="@+id/edit_1"
        android:imeOptions="actionNext"
        />

</LinearLayout>

它对我有用,希望对您有所帮助。

To provide focusing from left to right and from top to bottom for EditText in ListView, you can use following XML options:

<?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_1"
        android:nextFocusRight="@+id/edit_2"
        android:imeOptions="actionNext"
        />

    <EditText
        android:id="@+id/edit_2"
        android:nextFocusRight="@+id/edit_3"
        android:imeOptions="actionNext"
        />

   <EditText
        android:id="@+id/edit_3"
        android:nextFocusRight="@+id/edit_4"
        android:imeOptions="actionNext"
        />

   <EditText
        android:id="@+id/edit_4"
        android:nextFocusDown="@+id/edit_1"
        android:imeOptions="actionNext"
        />

</LinearLayout>

It works for me and hope it helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文