当我滑动我的视图时,Oncreateview没有打电话?

时间:2014-02-11 07:57:29

标签: android android-fragments fragment slideshow

嗨我正在处理滑动片段,当用户点按按钮时绘制视图。使用此库SlidingMenu library。这个库工作得很完美。但是当我在片段类中的fragmentactivity中滑动视图时,我在Fragment类中面临一个问题,没有方法调用我在这里尝试的是我的代码:

FragmentActivity:此活动扩展了SlidingFragmentActivity(此活动位于提到的库项目中)        @覆盖     @SuppressLint( “NewApi”)     public void onCreate(Bundle savedInstanceState){         // TODO自动生成的方法存根         requestWindowFeature(Window.FEATURE_NO_TITLE);         super.onCreate(savedInstanceState);

    View view1 = getLayoutInflater().inflate(
            R.layout.activity_main, null);
    View view2 = getLayoutInflater().inflate(R.layout.menu_frame, null);
    View view3 = getLayoutInflater().inflate(R.layout.menu_frame_two, null);
    getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);   
    getSlidingMenu().setMenu(view2);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.menu_frame, new Fragment1()).commit();
    getSlidingMenu().setSecondaryMenu(view3);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.menu_frame_two, new Fragment2()).commit();
    setContentView(view1);
}

Fragment1.java此活动扩展了Fragment

   @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    System.out.println("oncreate view");
    View v = inflater.inflate(R.layout.my_fragment_layout, container, false);

            return v;
            }

    @Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    System.out.println("on activity created");
      }

    @Override
public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    System.out.println("onResume");
     }

    @Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    System.out.println("oncreate");
}

@Override
public void onAttach(Activity activity) {
    // TODO Auto-generated method stub
    super.onAttach(activity);
    System.out.println("onAttach");
}

@Override
public void onSaveInstanceState(Bundle outState) {
    // TODO Auto-generated method stub
    super.onSaveInstanceState(outState);
    System.out.println("on save instance state");
}

@Override
public void onHiddenChanged(boolean hidden) {
    // TODO Auto-generated method stub
    super.onHiddenChanged(hidden);
    System.out.println("onHiddenChanged");
}

@Override
public void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    System.out.println("onStart");
}



@Override
public void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    System.out.println("onPause");
}

@Override
public void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    System.out.println("onStop");
}

@Override
public void onViewStateRestored(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onViewStateRestored(savedInstanceState);
    System.out.println("onViewstaterestored");
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onViewCreated(view, savedInstanceState);
    System.out.println("onViewCreated");
}

当我滑动时,左侧视图右侧,上述方法未调用。但是当我点击菜单按钮时,oncreateview正在调用。

在点击内部我正在调用getSlidingMenu()。showMenu();这种方法。

但我想在视图上滑动时调用任何方法。我的代码中出现了什么问题?  为什么滑动时任何方法都没有调用片段内部?

任何人请帮帮我......谢谢。

1 个答案:

答案 0 :(得分:2)