Android fragment jump Activity,fragment jump fragment,activity Jump Fragment

Source: Internet
Author: User

Loading different fragment/fragment in the activityloaded in a differentFragment

Load (toggle) Multiple fragment in the main activity (fragment) (can also be understood as activity jump fragment) or primary fragment

    • Activity There is a fragment layout space in the layout, such as the ID named Main_ framelayout

    • Write two fragment classes that inherit from fragment, such as

fragmentaextends Fragment ( This inside loads your view and writes your events in this Fragment)

FRAGMENTB extends Fragment (similarly)

Note: View =inflater.inflate (r.layout. Fragmenta_layout, container, false); This sentence must be under the Oncreatview Method! , or error you can not find a half-day, I was half a day to find!!

    • In the main activity's Click event (trigger event) such as you want to click a This button to load Fragmenta

Execute the following code

Fragmenta fm1=new Fragmenta ();

FRAGMENTMANAGERFM = Getsupportfragmentmanager ();

    1. Fm.begintransaction (). replace (R.id.main_framelayout, FM1). commit ();

4 ) button B.C and so on, so you can load different fragment on an activity page, or jump from one activity to a different fragment

Fragmentto theActivity

1) Fragment to activity Jump is the normal intent jump

2) Execute the following code on the current fragment page:

3) Intent Intent = new Intent (getactivity (), mainactivity.class);

Fragmentto theFragment
  • if two fragment depend on an activity, such as one, you can use the switching method

  • @Override// Core Code

  • 2 public void OnClick (View v) {


  • 3// Get Fragment instances of

  • 4 Fragment fragment=new Fragment ();

  • 5// Get Fragment the manager

  • 6 Fragmentmanager Fragmentmanager=getfragmentmanager ();

  •  7        // turn on fragment , fragment and other operations such as additions and deletions.

  • 8 fragmenttransaction ft=fragmentmanager.begintransaction ();

  • 9// Jump to Fragment , the first parameter is the position to be replaced ID , the second parameter is the replacement Fragment

  • Ten ft.replace (r.layout.fragment1_layout,fragment);

  • One // Submit Things

  • Ft.commit ();

  • 13}

2 if two fragment depend on different activity, then jump directly avticity.


This article is from the "10055957" blog, please be sure to keep this source http://10065957.blog.51cto.com/10055957/1714453

Android fragment jump Activity,fragment jump fragment,activity Jump 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.