开发者

Get a layout inflater from the ApplicationContext

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜