-1

I wonder where container argument in onCreateView() method of Flagment come from , is that a ViewGroup of the activity which has this fragment or something else ? I wonder it cause i don't know what ViewGroup that xml of fragment attract to in this code .thanks for your time

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {


    return  inflater.inflate(R.layout.fragment_list,container,true);



}
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
Tú Anh Dư
  • 135
  • 1
  • 10

2 Answers2

0

The container parameter passed to onCreateView() is the parent ViewGroup (from the activity's layout) in which your fragment layout will be inserted. Rest you can refer to this link

Anmol317
  • 1,356
  • 1
  • 14
  • 31
0

Not sure why this question was down voted. IMO it's a good question trying to understand what the framework is giving us from its callbacks.

I have the same question, and after reading some official docs, here is my theory:

To make it more specific, I think the container is the FragmentContainerView in this example. Basically it's the resource id which you add your fragment to. For example, if we do

fragmentTransaction.add(R.id.container_view, fragment).commitNow();

Then the container is the ViewGroup identified by R.id.container_view.

Changda Li
  • 123
  • 1
  • 8