Get layout blowing from ApplicationContext

I follow this guide to implement custom settings. http://android-journey.blogspot.com/2010/01/for-almost-any-application-we-need-to.html . In method

@Override
protected View onCreateView(ViewGroup parent){
   ...
} 

The manual creates the elements programmatically and then returns the view. I would like to get a layout from an XML file. But the call is getLayoutInflater()not available there, how can I get the invoice layout to get the view stored in the file "progressbarpreference.xml"?

I have a static link to the application. The context is available if necessary.

thank

+5
source share
3 answers
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.yourcustomviewxml, layout);

, : AttributeSet Ian!

+2
LayoutInflater li = (LayoutInflater) ctx.getSystemService(Service.LAYOUT_INFLATER_SERVICE);

(ctx - ).

+14

Use a static link, suppose this is context.

rowLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.progress_bar, parent, false);

where progress_bar is the identifier of the linear layout.

+2
source

All Articles