查看在平板电脑上返回 null 但在 phone 上工作正常

View returning null on tablet but working fine on phone

我目前有以下内容;

setupHideKeyboard( findViewById( R.id.login_layout ), this );
public void setupHideKeyboard( final View view, final Activity activity ) {

    if ( !( view instanceof EditText ) ) {

        view.setOnTouchListener( new View.OnTouchListener() {
        // crashes on the above line

            public boolean onTouch( View v, MotionEvent event ) {

                hideSoftKeyboard( activity );
                view.setFocusableInTouchMode( true );
                view.requestFocus();
                return false;
            }

        });
    }

    if ( view instanceof ViewGroup ) {

        for ( int childView = 0; childView < ( ( ViewGroup) view ).getChildCount(); childView++ ) {

            View innerView = ( ( ViewGroup ) view ).getChildAt( childView );
            setupHideKeyboard( innerView, activity );
        }
    }

用于设置触摸侦听器以在未按下编辑文本时隐藏键盘,这在我的 HTC One M7 上运行良好,但在我的三星 Galaxy Tab S 10.5 上崩溃。

由于某种原因,视图在选项卡 s 上为空,但在 m7 上正常。 有什么明显的想法吗?

好像找不到 R.id.login_layout 大的 xml 和小的有不同的名字吗?

可能您的布局和 layout-large/layout-xlarge 文件夹中存在相同的布局文件。但是 login_layout 仅在布局文件夹文件中定义。因此,由于平板电脑将从 layout-large/layout-xlarge 获取 xml,因此 inflation 没有问题,但无法从该布局文件获取 login_layout 视图。因此你遇到了崩溃。