Go Fragment jump to activity or fragment

Source: Internet
Author: User

1.Fragment Jump to activity

Jumping from fragment is similar to jumping from activity, except that you first get to show the activity of this fragment through the Getactivity method of fragment, the specific code is this:

Button button = view.findViewById(xxx); button.setOnClickListener( new View.OnClickListener(      onClick(View view)   {          startActivity( new Intent(getActivity(), SettingActivity. class ));      }         ));



If you want to return a result, you can have two similar methods:
Jump directly from the fragment

Startactivityforresult (Intent, Request_code);

This notation receives the returned result to rewrite the Onactivityresult () method in fragment;
Jump from activity

Getactivity (). Startactivityforresult (Intent, Request_code);
This is the way to rewrite the Onactivityresult () method in the activity.

2. Fragment Jump to Fragment

Fragment newfragment = Newexamplefragment ();
Fragmenttransaction transaction =getfragmentmanager (). BeginTransaction ();
Transaction.replace (r.id.fragment_container,newfragment);
Transaction.commit ();

Go Fragment jump to activity or fragment

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.