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;