Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中将焦点从一个编辑框切换到另一个编辑框_Android - Fatal编程技术网

如何在android中将焦点从一个编辑框切换到另一个编辑框

如何在android中将焦点从一个编辑框切换到另一个编辑框,android,Android,我有三个编辑框,每个框只能输入一个数字。当我输入第一个框的值时,焦点应该从第一个框移到第二个框。在输入值到第二个框后,它的焦点应该自动移到第二到第三个框,就像我需要做的那样。有人能帮我吗?你可以使用requestFocus()API将焦点从代码转移, 使用textWatcher继续侦听文本,一旦达到指定的限制,请调用EditTextreference.requestFocus()以转移焦点。您可以使用requestFocus()API从代码中转移焦点, 使用textWatcher继续侦听文本,一

我有三个编辑框,每个框只能输入一个数字。当我输入第一个框的值时,焦点应该从第一个框移到第二个框。在输入值到第二个框后,它的焦点应该自动移到第二到第三个框,就像我需要做的那样。有人能帮我吗?

你可以使用requestFocus()API将焦点从代码转移,
使用textWatcher继续侦听文本,一旦达到指定的限制,请调用EditTextreference.requestFocus()以转移焦点。

您可以使用requestFocus()API从代码中转移焦点,

使用textWatcher继续侦听文本,一旦达到指定的限制,调用EditTextreference.requestFocus()以转移焦点。

当EditText长度大于1时,此代码将焦点从一个EditText移动到另一个EditText

   EditText et1,et2;

    et1 = (EditText)findViewById(R.id.id1);
    et2 = (EditText)findViewById(R.id.id2);

   et1.addTextChangedListener(new TextWatcher()
    {
        public void afterTextChanged(Editable s)
        {
            // Abstract Method of TextWatcher Interface.
        }
        public void beforeTextChanged(CharSequence s,
        int start, int count, int after)
        {
        // Abstract Method of TextWatcher Interface.
        }
        public void onTextChanged(CharSequence s,
        int start, int before, int count)
        {
            Integer textlength = et1.getText().length();
            if(textlength>=1){      //If text length greater than 1 move to next EditText

                et2.requestFocus();

            }

        }
    });

当EditText长度大于1时,此代码将焦点从一个EditText移动到另一个EditText

   EditText et1,et2;

    et1 = (EditText)findViewById(R.id.id1);
    et2 = (EditText)findViewById(R.id.id2);

   et1.addTextChangedListener(new TextWatcher()
    {
        public void afterTextChanged(Editable s)
        {
            // Abstract Method of TextWatcher Interface.
        }
        public void beforeTextChanged(CharSequence s,
        int start, int count, int after)
        {
        // Abstract Method of TextWatcher Interface.
        }
        public void onTextChanged(CharSequence s,
        int start, int before, int count)
        {
            Integer textlength = et1.getText().length();
            if(textlength>=1){      //If text length greater than 1 move to next EditText

                et2.requestFocus();

            }

        }
    });

谢谢你的回复。你有什么样的代码吗?这样我就能更好地理解了。。我不会,我会说,搜索textwatcher类的用法,然后它只是一行调用requestfocus。谢谢你的回复。你有任何示例代码吗。这样我可以更好地理解。。我可以说,我没有搜索textwatcher类的用法,而只是调用requestfocus的一行代码。