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)
精彩评论