繁体   English   中英

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

[英]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 );
        }
    }

用来设置触摸式监听器以在不按下edittext时隐藏键盘,这在HTC One M7上很有效,但在Samsung Galaxy Tab S 10.5上崩溃了。

由于某些原因,该视图在选项卡上为空,但在m7上为正常。 有什么明显的主意吗?

就像找不到R.id.login_layout ,大型xml与小型xml具有不同的名称吗?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM