tobykurien / Xtendroid

Xtendroid is a DSL (domain-specific language) for Android that greatly reduces boilerplate code while providing great tooling support
MIT License
242 stars 23 forks source link

@AndroidActivity and @AndroidFragment magic @+id/name -> View name field generation broken for @CustomView(Groups) #69

Open Buggaboo opened 9 years ago

Buggaboo commented 9 years ago

A field should be generated on the custom ViewGroup, Fragment and Activity according to the @+id/name provided in the layout/viewgroup.xml, also custom Views and ViewGroups.

Right now it only works for anything from android.widget.*, but not for any other derived types, i.e. custom Views. I recall that the

isAssignable(ViewType, View)

in the generator code should handle all types deriving from View or ViewGroup.

I'll have a look.

tobykurien commented 9 years ago

I haven't tested this issue yet, but it may be related to a change I made to prevent CardView from crashing the build: https://github.com/tobykurien/Xtendroid/commit/3e5f805b325a5d669b1677b1072786cd5591a5e7

Buggaboo commented 9 years ago

Aha, thanks for the heads up. That try catch interrupts my isAssignableFrom. What is the problem exactly with CardView?

@tobykurien Do you think the isAssignableFrom can be extended to include CardView?

Two birds one stone? Two girls one cup?

tobykurien commented 9 years ago

IIRC the default constructor of CardView always throws an exception, thus breaking the code. I worked around it by ignoring CardView specifically, i.e. it will not be auto-generated into the code, but is still accessible the old-fashioned way using findViewById or by adding an @AndroidView for it.

maannajjar commented 9 years ago

Hey all, I faced this issue as well after updating Xtend to 2.8.1 (from 2.7). @Buggaboo 's fix didn't resolve the issue for me, it still won't generate getter for my custom views. I did further investigation and noticed Class.forName is always throwing ClassNotFoundException for my view classes. However, I tried using findTypeGlobally and it worked. Here's my change that made it work https://github.com/maannajjar/Xtendroid/commit/f111e39a34a8093c9bb68a371b08c1b8d49df240

tobykurien commented 9 years ago

Thanks, @maannajjar - please send that as a pull request and I'll merge it. I'm also still having issues with cardview and custom views