Symon_9851 Symon_9851 - 1 year ago 485
Android Question

Is it possible to manually call onCreateView in a Fragment?

Is it possible to manually call the method

in a
or, if not, is there some way I can simulate this invocation?

I have a
with tabHost. Each tab contains a
and I want to refresh the
's view when I press the "Refresh" button. More specifically, I want to re-call the

My code currently looks like:

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
// Inflate the layout for this fragment
view= inflater.inflate(R.layout.fragment_hall, container, false);

layoutExsternal = (RelativeLayout) view.findViewById(;
layoutHall = (RelativeLayout) view.findViewById(;


return view;


public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
Log.d("itemSelected1", this.getClass().getSimpleName());

switch (item.getItemId()) {

//HERE I want to insert a method for refresh o redraw

return true;

return super.onOptionsItemSelected(item);


Answer Source

I have resolved my question. I replace the current fragment with itself, but before I have saved a reference of current fragment and then i close life cycle of current fragment invoking onDestroy(). I recall it with "newFragment" variable.


switch (item.getItemId()) { case //THIS IS THE CODE TO REFRESH THE FRAGMENT. FragmentManager manager = getActivity().getSupportFragmentManager(); FragmentTransaction ft = manager.beginTransaction(); Fragment newFragment = this; this.onDestroy(); ft.remove(this); ft.replace(container.getId(),newFragment); //container is the ViewGroup of current fragment ft.addToBackStack(null); ft.commit(); return true; }