0

我有一个奇怪的场景,在我得到一个空指针错误之后,我的 DrawerLayout在更改之前onOrientationChange已经被初始化。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,我正在手动处理方向更改。谢谢

4

1 回答 1

0

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

<activity android:name="Your Activity Name"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="adjustPan"/>
于 2013-10-08T08:22:58.373 回答