【发布时间】:2015-08-04 09:40:25
【问题描述】:
我目前有以下;
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 上崩溃。
由于某种原因,tab s 上的视图为 null,但在 m7 上很好。 任何明显的想法为什么?
好像找不到R.id.login_layout 大xml 和小xml 有不同的名字吗?
【问题讨论】: