Create common panel is designer or code?

sconlon

Active Member
Licensed User
Longtime User
Throughout my app I want to have a fullwidth panel of 50dip height which has 5 buttons that can be used when in any of the 6 activities and layouts that the app contains. I have created the panel and buttons in the designer for the main layout and it would seem that I also have to do the same for each layout file. Would it be better perhaps to create the panel in code and run it after each layout file is loaded?
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Erel has got the layout loading very quick where there is almost no difference in load times for code vs. designer. It mostly comes down to preference- if you like to see things visually use the designer, if you like seeing by code use code.

Code may be easier to copy and paste for some, and when you use containers like panels you usually load a layout twice (Once for panel then again to populate panel) or do it by code either all the way or in combination with loading the panel layout then filling it by code. Depending on how many layouts you use by code though your compiled file size may be bigger in the end than having the one Designer layout that is reused. Class and Libraries can help though and I made some already I use myself.

For your example you may want to look at other flows with Action Bars or load your buttons at the top and some type of sliding pager for the content that is all in one activity.
 
Upvote 0

sconlon

Active Member
Licensed User
Longtime User
Thanks for the advice. If I want to do it in the designer is there a way to copy views, in this case the panel and buttons, from one layout file to another. This would save on having to add these views manually to each layout. I know I could use the main layout as the basis for the others but I already have them all designed and just want to add this button panel to each.
 
Upvote 0

sconlon

Active Member
Licensed User
Longtime User
Thanks Klaus. What then is the best way to handle the button click events? Will I need to have this code in each activity which seems a bit wasteful or is there some other approach to have common code somewhere?
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
You will have to handle the click event in each activity but you can have a code module that runs the common code and reference this from the click event, depending on your code you may need a reference to which activity you are currently in.
 
Upvote 0
Top