Android Question best way to do some kind of templating or inheritance

leitor79

Active Member
Licensed User
Longtime User
Hi,

I know inheritance is not supported (yet?).

I have some activities and I'd like to give all of them the same look&fell and share some controls (like a navigatordrawer).

So, using inheritance, I would define the navigatordrawer on the base class and inherit it form the children. But since this is not supported I'm wondering: which would be the best approach to have the same "suff" in all my activities wihouth having to touch the code of all of them if I need to make some change?

Regards!
 

LucaMs

Expert
Licensed User
Longtime User
So, I should have, in each Activity, something like:

B4X:
Sub Globals
    Private MyTemplate As clsMyTemplate

Sub Activity_Create
    MyTemplate.Initialize(Activity)

But then I have to declare the views in the activity and the class should expose the views' events, right?
 
Upvote 0

leitor79

Active Member
Licensed User
Longtime User
thanks for the answer! very nice!

I have one question regarding your interchange... should MyTemplate.Initialize(Activity) be called before or after the current activity's call to loadlayout?

Thank you very much!
 
Upvote 0

leitor79

Active Member
Licensed User
Longtime User
Hi again,

What if I have a button on my template class, and I want it to fire a sub on the activity I implement it? I think about a callsubdelayed, guided by a some kind of flag marking the activity it is implemented and therefore should be called, but this solution... too little ooped, too "unclean" seem to me...

Regards,
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi again,

What if I have a button on my template class, and I want it to fire a sub on the activity I implement it? I think about a callsubdelayed, guided by a some kind of flag marking the activity it is implemented and therefore should be called, but this solution... too little ooped, too "unclean" seem to me...

Regards,
I don't know what you exactly mean.
I hope the test project I'm attaching can help you.
 

Attachments

  • Template class test.zip
    8.3 KB · Views: 166
Last edited:
Upvote 0
Top