How to use inflater method within the fragment

doubter picture doubter · Jan 25, 2014 · Viewed 12.4k times · Source

Hi I am working with android.I had tried to inflate a layout into the fragment, but it shows error in the code "method getLayoutInflater() is undefined for the class". how can I access layout within the fragments ??? please help me I am new to android .Thanks

here is my code

        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
         listView1.addHeaderView(header); 

Answer

Gopal Gopi picture Gopal Gopi · Jan 25, 2014

getLayoutInflater() is a method of Context

use getActivity().getLayoutInflater()... valid after onAttach() call back is called in Fragment