6

I'm following that guide for implementing a custom preference. http://android-journey.blogspot.com/2010/01/for-almost-any-application-we-need-to.html. In the method

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

The guide creates the elements programmatically and then returns the view. I'd like retrieve the layout from a xml file. But the call getLayoutInflater() is not accesible there how can I retrieve a layout inflater for get the view stored in the file "progressbarpreference.xml"?

I have a static reference to the application Context available if needed

Thanks

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
Addev
  • 31,819
  • 51
  • 183
  • 302

3 Answers3

18
LayoutInflater li = (LayoutInflater) ctx.getSystemService(Service.LAYOUT_INFLATER_SERVICE);

should do the trick (ctx is your application context in this case).

2

Use the static reference, suppose if it is context.

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

where progress_bar is the id of the linear layout.

2
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.yourcustomviewxml, layout);

Got this from a question I asked: How to pass AttributeSet to custom View Thanks Ian!

Community
  • 1
  • 1
atraudes
  • 2,368
  • 2
  • 21
  • 31