DrawerLayout上方向更改期间的空指针

时间:2013-10-08 08:19:28

标签: java android nullpointerexception screen-orientation navigation-drawer

我有这种奇怪的情况,其中onOrientationChange我得到空指针错误后,我的DrawerLayout在更改之前已在onCreateView初始化。

mDrawerLayout = (DrawerLayout) rootView.findViewById(R.id.drawer_layout);

我在这一点上变得空虚,

 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());

         }
           }

更新:

我不是也不会使用 configChanges ,我正在手动处理方向更改。感谢

1 个答案:

答案 0 :(得分:0)

在你的清单中试试这个......

<activity android:name="Your Activity Name"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="adjustPan"/>