开发者

Possible to get reference to a View without setting the ContentView of an Activity

I want to be able to get reference to a RelativeLayout in the same way as

RelativeLayout relative = (RelativeLayout)findView开发者_StackOverflowById(R.id.relative);

but without setting the ContentView of the Activity. I think it may have something to do with Infalter? My ultimate aim is to get this and add it as a child view of a custom view object.


Yes, you can use LayoutInflater. Example:

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);    
View mv = inflater.inflate(R.layout.yourlayout, null);

And then you could...

RelativeLayout relative = (RelativeLayout)mv.findViewById(R.id.relative);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜