Getsuppfrfragmentmanager must be used in FragmentActivity and its subclass. fragmentactivity

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.