开发者

Get a layout inflater from the ApplicationContext

开发者 https://www.devze.com 2023-03-28 06:10 出处:网络
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

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 l开发者_StackOverflow社区ayout inflater for get the view stored in the file "progressbarpreference.xml"?

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

Thanks


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

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


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消