自动对焦接下来的TextView自动对焦、接下来、TextView

2023-09-06 03:05:59 作者:联合国秘书长i

我有一个的TextView Android版本:最大长度设置为 3 和另一个具有 Android版本:最大长度设置为 7

I have a TextView with android:maxLength set to 3 and another with android:maxLength set to 7.

我要集中自动移动到第二个的TextView 一旦第一的TextView 被填满。如何实现这一点没有继承的TextView 和编写自定义实现?

I want focus to automatically move to the second TextView once the 3 chars of the first TextView are filled up. How to achieve this without inheriting TextView and writing a custom implementation?

推荐答案

我还没有尝试过,但是这可能工作。

I haven't tried but this might work.

设置一个监听器触发当文字被改变,这种用途

Setup a listener to fire when the text was changed, for this use

addTextChangedListener(TextWatcher watcher)

在此基础上的文字长度,你可以请求焦点更改到下一个字段。

Then based on the text length you can request the focus change to the next field.

。这实际上并没有给予重点这一观点。

If you want to find out the next field you can call View.focusSearch(View.FOCUS_FORWARD) Find the nearest view in the specified direction that can take focus. This does not actually give focus to that view.