Reinmarius Reinmarius - 6 months ago 21
Android Question

Can't access class attribute after getChildAt()

Following Scenario:

I create a class 'exampleClass' with an inflated view. The class has an atribute

'String A'
with a corresponding getter.

I create an instance of this class. No surprise for me that i can call both
Log.v(LOG_TAG, instance.toString());
follwed by
Log.v(LOG_TAG, instance.getA());
which results in the right outputs.

I add this instance to a ViewGroup called container. Then i call
. That gives me as expected, the same output as above with
Log.v(LOG_TAG, instance.toString());
, no difference.

What's not working is to call
(or any other member). Only methods that belong to the inflated view are available.

So is there a way to get access to attributes and members? Any other background information about this topic is also appreciated.

Answer Source

Cast target type to container.getChildAt(0) before using getSideA method.

((TargetClassType) container.getChildAt(0)).getSideA()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download