Getsuppfrfragmentmanager must be used in FragmentActivity and its subclass. fragmentactivity
Getsuppfrfragmentmanager must be used in FragmentActivity and its subclass !!
About Android drawer navigation !!
* Custom sidebar
Create a Fragment: CarlozLibFragment. java, and create a layout carloz_lib_webview.xml for it. There is a WebView control in it, by the way, in AndroidManifest. add Intent access permissions in xml; override the onCreateView method in CarlozLibFragment to allow WebView to access my personal website (http://carloz.duapp.com );
public class CarlozLibFragment extends Fragment { private String TAG = "CARLOZ"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View root = inflater.inflate(R.layout.carloz_lib_webview, container, false); WebView wv =(WebView)root.findViewById(R.id.wv); Log.d(TAG, "load url: carloz lib"); wv.loadUrl("http://carloz.duapp.com"); return root; }}
Delete the ListView-related content in onCreateView in NavigationDrawerFragment. java and replace it with the custom layout diy_slider_content.xml (directory res/layout). diy_slider_content defines a button to open the newly created CarlozLibFragment;
@ Overridepublic View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {View root = inflater. inflate (R. layout. diy_slider_content, container, false); root. findViewById (R. id. btnJump ). setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {if (mDrawerLayout! = Null) {// hide the sidebar mDrawerLayout. closeDrawer (mFragmentContainerView);} if (mCallbacks! = Null) {mCallbacks. onGotoCarlozLibClicked () ;}}); return root ;}
OnGotoCarlozLibClicked () is a custom interface, which is added to the static interface NavigationDrawerCallbacks.
Public static interface NavigationDrawerCallbacks {/*** Called when an item in the navigation drawer is selected. */void onNavigationDrawerItemSelected (int position); // pass the callback to the main interface void onGotoCarlozLibClicked ();}
This callback method needs to be implemented in the SliderActivity of the main interface, because the main interface implements the NavigationDrawerFragment. NavigationDrawerCallbacks Interface
@ Overridepublic void onGotoCarlozLibClicked () {// you need to implement NavigationDrawerFragment. method added in java Callback // Add fragment CarlozLibFragment getsuppfrfragmentmanager () to the container (). beginTransaction (). replace (R. id. container, new CarlozLibFragment ()). commit ();}
The running result is as follows:
Here reference: http://www.cnblogs.com/carlo/p/4726719.html