mercredi 20 septembre 2017

Kotlin / Android app - changing view elements from outside Activity

I am using kotlin lang to create my Android app.

I wanted to create an object (singleton) that would specialise in modyfying my main activity's view components (like buttons etc) dynamically and would be used by my main activity itself.

Some problems arose. First of all, the object is (of course) not Activity type, so I cannot use for example findViewById and other Activity's functions etc. I tried to resolvye this by passing main Activity by object's constructor, but it's not allowed - since objects cannot have their constructors.

Additionally I am not sure, if this app design is acceptable according to at least good practices. If not really - what design pattern should I use to separate logic of how to change my layouts from the code that only will modify view elements?

Thank you in advance for any suggestons.

Aucun commentaire:

Enregistrer un commentaire