嗨我正在滑動片段,當用戶點擊按鈕繪製視圖。通過使用這個庫SlidingMenu library。這個庫工作得很好。但是我在Fragment類中遇到了一個問題,當我在片段類中的我的fragmentactivity中滑動視圖時,沒有方法正在調用我在這裏嘗試的是我的代碼:當我滑動視圖時,Oncreateview不會調用?
FragmentActivity:this activity延伸SlidingFragmentActivity(此活性是在側abvoe提到庫項目) @Override @SuppressLint( 「NewApi」) 公共無效的onCreate(捆綁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此活動當我滑動的視圖左側是右側上述方法不調用延伸片段
@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();這種方法。
但我想調用任何方法,當我滑動視圖。我的代碼中有什麼問題? 爲什麼有些方法在滑動時不會調用片段內部?
任何人請幫助我..提前感謝。