Android Question Side Menu Click Events / Code

jgm2

New Member
Licensed User
Longtime User
Hi

I am producing an App that has a small icon to slide a menu in from the side on different sections. This contains multiple elements such as a search box, buttons, images and labels etc so I have decided to create a layout file and load it into a dynamically created panel. I have created a function in a code module to do this that uses the following:

B4X:
Dim Panel1 As Panel
Panel1.Initialize("LeftMenuPanel")
Activity.AddView(Panel1, 0, 0, PosX, 100%y)
Panel1.LoadLayout("SlideNav")

PosX being set to two thirds of the screen width. This works great up to now, however I want to run functions when buttons are being clicked on this layout and a few other things such as setting a custom font from a ttf so the menu is similar to an activity.

I can have the click subs in each activity module that I run the menu from although this is copying code and doesn't seem like the best solution. It almost seems like I need 2 activities running at the same time taking up different parts of the screen although this doesn't seem to be possible.

Can anyone tell me what the best way to produce this will be?

Thanks for any help.
 

stevel05

Expert
Licensed User
Longtime User
Look at moving the code module to a class, then you can catch the events within the class and pass the appropriate subs to each activity with callsub. Or just control the menu from the class.

It's difficult to give you an exact answer without knowing what the functions of the menu do.
 
Upvote 0

jgm2

New Member
Licensed User
Longtime User
I had already looked through the libraries available and I thought that because the styling and options will be so custom it may be best to look at making my own. It seems like using a class is a great option, think I missed the following from the class tutorial:

"Classes store a reference to the context of the activity or service module that called the Initialize sub. This means that classes objects share the same life cycle as the service or activity that initialized them."

It looks like I can access the objects from the layout after they have been loaded into the panel and handle click events from within the class. Controlling the menu from a class seems to work perfectly, thanks!
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I had already looked through the libraries available and I thought that because the styling and options will be so custom it may be best to look at making my own. It seems like using a class is a great option, think I missed the following from the class tutorial:

"Classes store a reference to the context of the activity or service module that called the Initialize sub. This means that classes objects share the same life cycle as the service or activity that initialized them."

It looks like I can access the objects from the layout after they have been loaded into the panel and handle click events from within the class. Controlling the menu from a class seems to work perfectly, thanks!
Did you look at my Sliding Sidebar class?
 
Upvote 0
Top