Although fragment is implemented as an object, it is independent of activity and can be used in multiple activity, a given fragment instance is bundled directly into the activity that contains it.
In particular, fragment can access activity through the getactivity () function, and it is easy to perform tasks similar to finding views in an activity layout:
View ListView = getactivity (). Findviewbyid (R.id.list);
Similarly, activity can call fragment's function Findfragmentbyid () or Findfragmentbytag () to get the fragment index from Fragmentmanager, for example:
Examplefragment fragment = (examplefragment) Getfragmentmanager (). Findfragmentbyid (r.id.example_fragment);
This article is from the "Mobile Platform Development" blog, make sure to keep this source http://liuxudong1001.blog.51cto.com/10877072/1886533
Fragment interacting with activity