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!!
Execute the following code
Fragmenta fm1=new Fragmenta ();
FRAGMENTMANAGERFM = Getsupportfragmentmanager ();
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