将焦点添加到微调器

azz*_*its 3 android spinner

在这里我有一个微调器和微调器下面的一些文本字段.当其中一个文本字段具有焦点时,我从微调器中选择一个项目,我看到焦点仍然在该文本字段上,现在我想要做的是,在选择的微调器项目上,我想将焦点从该文本字段更改为微调.有没有办法将焦点设置为微调器?喜欢,

    @Override
    public void onItemSelected(AdapterView<?> parent, View view,
            int position, long id) {
        //set focus to the spinner 
            }
        }
Run Code Online (Sandbox Code Playgroud)

小智 7

我遇到了类似的问题,并在此处找到了部分答案.

但是,我还必须从我的代码而不是XML文件中设置focusable(true)和focusableInTouchMode(true).在我在代码中设置可聚焦属性之前,我无法使其工作.以下是我项目的示例:

spinUoM.setFocusable(true);
spinUoM.setFocusableInTouchMode(true);

spinUoM.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus)
                DialogDefineRecipeActivity.this.spinUoM.performClick();
        }

    });
Run Code Online (Sandbox Code Playgroud)


azz*_*its 5

在我的情况下工作

    @Override
     public void onItemSelected(final AdapterView<?> parent, View view,
            final int position, long id) {

        parent.post(new Runnable() {
            @Override
            public void run() {
                spinner.requestFocusFromTouch();
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)