微调不重点 [英] Spinner does not get focus

查看:152
本文介绍了微调不重点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个活动中使用了4 EditText 字段和2个spinners。这些组件的顺序是2 EditText ,然后是2个spinners,然后是2 EditText 字段。

当我从 EditText 转到焦点(在软键盘的下一个按钮的帮助下)微调不获得焦点,焦点转移到位于微调器之后的下一个 EditText 字段。



我已经在微调器上使用了requestfocus(),但是没有成功。

我怎么确定微调获得焦点?

解决方案

我设法找到一个解决方案,然后重新定位我的微调。在微调控件的EditText 之前,添加这个监听器:

$ edit $ {
@Override
public boolean onEditorAction(TextView textView,int actionId,KeyEvent event){$ b $ if(actionId == EditorInfo.IME_ACTION_NEXT){
hideKeyboard();
textView.clearFocus();
spinner.requestFocus();
spinner.performClick();
}
return true;
}
}) ;

您还需要将这些行添加到能够获得焦点的spinner中:

  spinner.setFocusable(true); //可以在XML中完成首选

我的hideKeyboard函数只是我想添加的一个视觉细节所以键盘被隐藏:

pre $ private $ hide hideboardboard(){
InputMethodManager inputManager =(InputMethodManager)getSystemService(Context。 INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus()。getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}

希望我在这个棘手的问题上有所帮助。

标记 InputMethodManager.HIDE_NOT_ALWAYS 可以在中找到文档


I'm using 4 EditText fields and 2 spinners in an activity. The order of these components are 2 EditText, then 2 spinners and then 2 EditText fields.

The problem occurs when I transfer focus (with the help of soft keyboard next button) from EditText to spinner, spinner does not get the focus and the focus is transferred to the next EditText field that was placed after the spinners.

I have used requestfocus() on spinner, but it did not work.

How do I make sure the spinner gets focus?

解决方案

I managed to find a solution other then repositioning my Spinner. In the EditText before the spinner, add this listener:

editTextBefore.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_NEXT) {
            hideKeyboard();
            textView.clearFocus();
            spinner.requestFocus();
            spinner.performClick();
        }
        return true;
    }
});

You also need to add these line to able spinner to get focus:

spinner.setFocusable(true); // can be done in XML preferrable

My hideKeyboard function was just a visual detail that I wanted to add so the keyboard get hidden:

private void hideKeyboard() {
    InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

Hope I have helped in this tricky question.
The flag InputMethodManager.HIDE_NOT_ALWAYS can be found in the documentation.

这篇关于微调不重点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆