[英]Null Pointer during orientation change on DrawerLayout
I have this weird scenario wherein after the onOrientationChange
I got a Null Pointer Error, my DrawerLayout that has been initialized on onCreateView
before the change. 我有一个奇怪的场景,其中在
onOrientationChange
之后,我得到了一个空指针错误,该DrawerLayout在更改之前已在onCreateView
初始化。
mDrawerLayout = (DrawerLayout) rootView.findViewById(R.id.drawer_layout);
And I am getting null on this point, 在这一点上,我变得无言以对,
if(mDrawerList.getChildAt(position)!=null){
}
private void selectItem(int position, boolean InstanceStateNull) {
Log.d("selectItem", "inside");
//savePosition("position", position);
// update the main content by replacing fragments
Toast.makeText(getActivity(), "SELECT ITEM: "+ position, Toast.LENGTH_SHORT).show();
Log.d("SELECT ITEM: Position: ", ""+ position);
this.mDrawerList.setItemChecked(position, true);
this.mDrawerList.setSelection(position);
String selectedPid = null;
//use mDrawerList.getChildAt(position) for not having null pointer
if(mDrawerList.getChildAt(position)!=null)
{
//Extracts the string
TextView pid = (TextView)mDrawerList.getChildAt(position).findViewWithTag("pid");
selectedPid = pid.getText().toString();
Log.d("SELECT ITEM: SELECTED ITEM: ", ""+ selectedPid.toString());
Toast.makeText(getActivity(), "SELECTED ITEM: "+ selectedPid
, Toast.LENGTH_SHORT).show();
//saveSelecteditem("selectedItem", selectedPid);
}
else{
Log.i("DrawerList on Orientation Change: ", "Null");
//Log.i("DrawerList on Orientation Change: ", "Count" + mDrawerList.getAdapter().getCount());
}
}
Update: 更新:
I am not and will not be using the configChanges
, I am handling the orientation change manually. 我不是,也不会使用
configChanges
,而是手动处理方向更改。 Thanks 谢谢
Try this in your manifest... 试试你的清单...
<activity android:name="Your Activity Name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="adjustPan"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.