开发者

How do I programmatically instantiate elements defined in XML?

开发者 https://www.devze.com 2023-03-09 08:14 出处:网络
I\'m working on an Android application and can\'t seem to figure out how to either instantiate elements that are defined in XML, or create a new element and copy all of a given XML element\'s attribut

I'm working on an Android application and can't seem to figure out how to either instantiate elements that are defined in XML, or create a new element and copy all of a given XML element's attributes. Defining a new element's properties in code is really annoying, and开发者_如何学编程 I was hoping I wouldn't have to create a Java class for each new element type.


Are you looking for

View v = View.inflate(context, R.layout.yourlayout, root);


There are total three ways for get view

1) Using Inflater ex. View v = View.inflate(context, R.layout.yourlayout, root);
2) By making a new element ex. view v = new ImageView(context)
3) By mapping it with XMl ex. findViewById(R.id.elementId)
0

精彩评论

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