gpt4 book ai didi

android - Android requestFocus() 的问题

转载 作者:太空狗 更新时间:2023-10-29 12:58:13 25 4
gpt4 key购买 nike

下面是我为将焦点从一个编辑文本转移到另一个编辑文本而编写的一段代码,但是我在这个实现中遇到的问题是,焦点移动到特定的编辑文本,然后突然移动到下一个编辑文本。所以,我无法输入任何内容,因为焦点根本不在那个特定的编辑文本上。

//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:inputype 导致了这种“跳跃”行为。因此,如果我在 XML 中有 EditText1android:inputType="textCapSentences",则在 EditText1 上调用 requestFocus() > 使其在将焦点移动到下一个 View 之前短暂突出显示。

我不确定这是否是 Android 中的一个错误,或者它是否确实是我遗漏的其他东西。我尝试以编程方式设置 inputType 并在我的代码的各个点内使用 setInputType() 但它对我不起作用。所以现在我刚刚删除了 inputType 属性 & requestFocus() 正常工作。

关于android - Android requestFocus() 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3890151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com