Android Question Common functions

mitsusdev

Member
Licensed User
Longtime User
I would add the same functions (actionbar, admod, ecc,ecc) in each activity without re-write the code.

how i have to write the code one time ?

into class molune, code module or .......

thanks
 

DonManfred

Expert
Licensed User
Longtime User
I have the same problem. I want to use ahactionbar (and others) in ALL my activities.
Can you give a us a short example of doing this as a class? Maybe a little Class which "generates, initialize and places" just a label!? Would be really great!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have the same problem. I want to use ahactionbar (and others) in ALL my activities.
Can you give a us a short example of doing this as a class? Maybe a little Class which "generates, initialize and places" just a label!? Would be really great!


I can... but can you explain to me HOW ahactionbar works well??? i have layout problem, with it! (search my post, i'm writing an example for your question - and read my signature, lol)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
'Class module clsLayOutHelper
Sub Class_Globals
    Dim lbl As Label
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub

Public Sub CreateLabel(HostPanel As Panel, _
                              Text As String, _
                              Left As Int, Right As Int, _
                              Width As Int, Height As Int, _
                              EventName As String)

    lbl.Initialize(EventName)
    lbl.Text = Text

    HostPanel.AddView(lbl, Left, Right, Width, Height)
End Sub


Then, in each Sub Globals Activity:

B4X:
Private mLayOutHelper As clsLayOutHelper

And:

B4X:
    mLayOutHelper.CreateLabel(Activity, "Hello", 10dip, 10dip, 120dip, 45dip, "")

(I have not tested it!)


Tested: don't works :)

Now works!
 
Last edited:
Upvote 0

mitsusdev

Member
Licensed User
Longtime User
thank erel

i have done a litte example project and work fine

but how i manage events of class ?

for example on action the click go to on event of class and don't go on event on activity.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can forward the events to the calling module using the me keyword. See attached.
 

Attachments

  • ClassTest.zip
    8.6 KB · Views: 172
Upvote 0

mitsusdev

Member
Licensed User
Longtime User
thanks, but the example project does'nt work, return:

java.lang.Exception: Sub button_click signature does not match expected signature.

when click on button
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Ahh it's one of those that works in the rapid debugger but not in legacy. The rapid debugger is more forgiving of type mismatches. Try this one.
 

Attachments

  • ClassTest.zip
    8.7 KB · Views: 168
Upvote 0
Top