'findViewById' unavailable in custom ArrayAdapter

Hello fellow programmers,

I am making an app for android which uses a listview. I made a custom ArrayAdapter which overrides the “getView” method so I have control over the Icons and text. In the implementation of this method I can’t use ‘findViewById’. This is because there is no reference to the MainActivity, but how do add this? I tried changing the constructor (adding aInstance : MainActivity), but it gives me “an explicit inherited constructor is needed” error. How do I solve this? I posted a related question a while ago and thankfully I was able to solve that with your help!

Thanks in advance,
Oznov

The ArrayAdapter constructor takes a Context parameter, which is typically passed in to be the Activity, as Activity inherits from Context. Just store that context in an overridden constructor, and cast to Activity in order to call findViewById.

The ListView sample app uses a custom array adapter with an overridden constructor, but doesn’t store it away like you could do.

Master! That works.

Thanks,
Oznov