Fragment summary, fragment

Source: Internet
Author: User

Fragment summary, fragment

Recently, the new get fragment is easy to use. It is more convenient and concise than tab.

The specific usage is not described in detail. First, write down the implementation such as jump:

1. Replace fragment

R. id. button:

<Span style = "font-size: 18px;"> setContentFragment (Fragment to be replaced. class, <span style = "font-family: Arial, Helvetica, sans-serif;"> R. id. fragment_contiainer); </span>
Break;

2. jump from one fragment (A) to another fragment (B). Fragment can only be A part of the activity and cannot be jumped to and run independently. The jump can only be A jump of activity.

Add the corresponding method to the main file:


Public void switchToXueche (){

Radio_group_main.check (R. id. rb_leaning );

}


Call this method in A fragment:


Case R. id. button :{

 

(MainActivity) getActivity (). switchToXueche ();

 

}

3. jumping from an activity (A) to A fragment is the same as 2. fragment cannot be jumped to and run independently. You can only jump to the relevant activity during the jump, you only need to pass corresponding parameters to the activity to define the fragment parameter of the activity in the main file that meets the conditions:

Protected void onNewIntent (Intent intent ){

Super. onNewIntent (intent );

Int index = intent. getIntExtra ("index", 1 );

If (index = 2 ){

Radio_group_main.check (R. id. rb_leaning );

SetContentFragment (XuecheFragment. class,

R. id. fragment_contiainer );

}

}


Add the following parameters when redirecting activity:


Case R. id. button:

 

Intent intent = new Intent (HuodongxiangqingActivity. this,

MainActivity. class );

Intent. putExtra ("index", 2 );

 

BaseStartActivity (intent );

 

Break;



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.