将焦点添加到微调器 [英] Adding Focus to a spinner
问题描述
在这里,我有一个微调框和在微调框下方的一些文本字段.当文本字段之一具有焦点时,我从微调器中选择一个项目,然后看到焦点仍在该文本字段上,现在我想做的是,在所选微调器项目上,我想将焦点从该文本字段更改为微调器. 有什么办法可以将焦点设置到微调器上吗?
Here i have a spinner and some text fields below the spinner. when one of the text field has focus, i select an item from spinner and i see the focus is still on that text field, Now what i want to do is, on spinner item selected i want to change focus from that text field to the spinner. Is there any way to set focus to spinner?like,
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
//set focus to the spinner
}
}
推荐答案
I had a similar problem and found part of the answer here.
但是,我还必须从代码而不是XML文件中设置focusable(true)和focusableInTouchMode(true).在代码中设置可聚焦属性之前,我无法使其正常工作.这是我的项目中的一个示例:
However, I also had to set focusable(true) and focusableInTouchMode(true) from my code and not the XML file. I couldn't get it to work until I set the focusable properties in the code. Here is a sample from my project:
spinUoM.setFocusable(true);
spinUoM.setFocusableInTouchMode(true);
spinUoM.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
DialogDefineRecipeActivity.this.spinUoM.performClick();
}
});
这篇关于将焦点添加到微调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!