问题描述
我在一个活动中使用了4 EditText
字段和2个spinners。这些组件的顺序是2 EditText
,然后是2个spinners,然后是2 EditText
字段。
当我从 EditText
转到焦点(在软键盘的下一个按钮的帮助下)微调不获得焦点,焦点转移到位于微调器之后的下一个 EditText
字段。
我已经在微调器上使用了requestfocus(),但是没有成功。
我怎么确定微调获得焦点?
我设法找到一个解决方案,然后重新定位我的微调。在微调控件的EditText 之前,添加这个监听器: 您还需要将这些行添加到能够获得焦点的spinner中: 我的hideKeyboard函数只是我想添加的一个视觉细节所以键盘被隐藏: 希望我在这个棘手的问题上有所帮助。 I'm using 4 The problem occurs when I transfer focus (with the help of soft keyboard next button) from 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: You also need to add these line to able spinner to get focus: My hideKeyboard function was just a visual detail that I wanted to add so the keyboard get hidden: Hope I have helped in this tricky question. 这篇关于微调不重点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
$ 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.setFocusable(true); //可以在XML中完成首选
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
可以在。EditText
fields and 2 spinners in an activity. The order of these components are 2 EditText
, then 2 spinners and then 2 EditText
fields. 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. 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;
}
});
spinner.setFocusable(true); // can be done in XML preferrable
private void hideKeyboard() {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
The flag InputMethodManager.HIDE_NOT_ALWAYS
can be found in the documentation.