在Android的选择时,设置焦点微调 [英] Set focus on spinner when selected in android

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

问题描述

我有多个的EditText和微调框控件的垂直滚动布局。
问题是,当我选择选择屏幕滚动返回到最后的EditText后,在此之前微调编辑任何微调选项。重点仍然用最后的EditText我编辑。有没有一种方法,我可以保持专注与当前选定的微调。

I have a vertical scrolling layout with multiple EditText and Spinner controls. Problem is when i choose any spinner option after selection the screen scrolls back to the last EditText is was editing before this spinner. The Focus remains with the last EditText i was editing. Is there a way i can keep focus with the current selected spinner.

我要寻找能够从布局XML或一些通用的方法全部纱厂实施适用于所有纺纱的解决方案。

I am looking for a solution that can be implemented on all spinners from layout XML or some generic method to apply to all spinners.

推荐答案

我解决了这个问题,答案Ryderz的帮助。这里是code:

I solved the problem with the help of Ryderz answer. here is the code :

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
scrollView = (ScrollView) findViewById(R.id.sv_main);
    scrollView.setOnTouchListener(new OnTouchListener() {
        // to solve focus problem on scrolling
        public boolean onTouch(View v, MotionEvent event) {

            IBinder windowToken = null;
            if (myEditText1.hasFocus()) {
                myEditText1.clearFocus();
                windowToken = myEditText1.getWindowToken();
            }
            if (myEditText2.hasFocus()) {
                myEditText2.clearFocus();
                windowToken = myEditText2.getWindowToken();
            }
            if (myEditText3.hasFocus()) {
                myEditText3.clearFocus();
                windowToken = myEditText3.getWindowToken();
            }
            if (windowToken != null) {
                imm.hideSoftInputFromWindow(windowToken, 0);
            }
            scrollView.requestFocusFromTouch();
            return false;
        }
    });

然后我设置了android:可调焦=真我textViews使上滚动时,焦点从EDITTEXT删除的时候,Textviews可挑的焦点。通过这种方式,用户不会看到屏幕上出现任何集中控制。

Then I set the android:focusable="true" for my textViews so that on scroll when focus is removed from editText then the Textviews can be picked for focus. In that way the user doesn't see any focused control on screen.

这篇关于在Android的选择时,设置焦点微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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