Reputation: 706
Normally in an Android layout file if you want to create a custom view you have to fully qualify the path of the class.
<com.blah.blah.blah.Widget>
....
</com.blah.blah.blah.Widget>
Is there anyway to import a class in the XML so you don't have to repeat package names? Some of my package names are quite long and its just a huge pain in the butt when some layouts have many custom views.
The ability to do...
<import path="com.blah.blah.blah.MyWidget"/>
<MyWidget>
...
</MyWidget>
Would make my life much easier.
Obviously that import tag doesn't currently exist but is there a way to extend the inflator to add it?
If not is there another way to do this?
Upvotes: 1
Views: 171
Reputation: 1006799
Is there anyway to import a class in the XML so you don't have to repeat package names?
No, sorry.
Obviously that import tag doesn't currently exist but is there a way to extend the inflator to add it?
In theory, you can set a factory on LayoutInflater
, which gets control during the inflation process, and might be usable to accomplish this. However, that would only work for a LayoutInflater
you use directly, not for any used by the system (e.g., setContentView()
, default Adapter
inflation).
Upvotes: 1