Android Question Multiple pages

John Horlock

Member
Licensed User
Hi

I'm using AppCompat demo as a starting point but i've not found what i'm looking for at the moment. ( still learning the naming of everything )

I want to have all my code broken into its own classes with multiple pages.
I have the LEFT menu working - but i want to GOTO a page when i click on the option in the left menu.

What is the best way to do this?
I've tried having a MASTER screen which has the ACtoolBarLight on it and a Panel - and i load my screen into the Panel, ( but the old ones is till rpesent, so thats not working )

I want o make it as light / as possible - and i dont want to have to declare a ACtoolBarLight on each screen and set up the activity for the menu for every page... Is this Possible?

Thanks
 

John Horlock

Member
Licensed User
thanks. Yes i come from MVC .net and cordova programming....

So just trying to find a pattern which works for my thought process.

Reading that it looks like if i use the B4Xdrawer - then it will work better across iOS / android

It would be nice if an Activity module was linked to a screen view - that way referencing items could be done ( it may be like this - just not found it yet )
 

John Horlock

Member
Licensed User
This is structure i had in mind

Master Page - this has the left sliding menu on it - the menu options are static and don;t change throughout the app.

Page 1: this page is displayed first
Page 2: Users can navigate to this page from the menu or other options
Page X:Users can navigate to this page from the menu or other options

The reason for the MASTER page - was so i did not have to declare the menu everytime.

Menu / Setup code on MASTER
Drawer.Initialize(Me, "Drawer", Activity, 300dip)
Drawer.CenterPanel.LoadLayout("Dashboard")
ToolbarHelper.Initialize
ToolbarHelper.ShowUpIndicator = True 'set to true to show the up arrow
Dim bd As BitmapDrawable
bd.Initialize(LoadBitmap(File.DirAssets, "hamburger.png"))
ToolbarHelper.UpIndicatorDrawable = bd
DashBoard_ACToolBarLight1.InitMenuListener
Drawer.LeftPanel.LoadLayout("Left")



Menu Option - Page 1 - CLICKED: How do i load the next view / page if i have everything separated out ...


My app is going to grow ( thinking of rewriting my ionic app in B4X ) so i MUST have a sensible layout from the start.
 

RichardN

Active Member
Licensed User
How about a single activity with AppCompat menu linking to the desired pages... Some pages are constructed on panels that are 100% x/y therefore hiding the menu, others leave the menu visible to permit access.

Don't forget to add an empty PanelX_Click event to ensure clicks are consumed and not passed through to views behind.
 

John Horlock

Member
Licensed User
Ok i've had a look at the SQL example and it uses StartActivity....
However i'm using B4XDrawer this does not seem to be the same... Am i missing something here?

Due to the complexity of some of the processes - I really need this to be broken into code per page...

I'm currently trying to A Activity per screen - which recreates the Menu ... but it keeps crashing at the moment.
 

DawningTruth

Active Member
Licensed User
How about a single activity with AppCompat menu linking to the desired pages... Some pages are constructed on panels that are 100% x/y therefore hiding the menu, others leave the menu visible to permit access.

Don't forget to add an empty PanelX_Click event to ensure clicks are consumed and not passed through to views behind.
Interesting approach. So you basically have everything in a single activity and in panels. You then manage what the user views by making panels visible, invisible and larger or smaller. With a persistent panel at the top for the menu.

Am I understanding you right?
 

DawningTruth

Active Member
Licensed User
Ok i've had a look at the SQL example and it uses StartActivity....
However i'm using B4XDrawer this does not seem to be the same... Am i missing something here?

Due to the complexity of some of the processes - I really need this to be broken into code per page...

I'm currently trying to A Activity per screen - which recreates the Menu ... but it keeps crashing at the moment.
You could use the Drawer as the equivalent of the Menu on my diagram above. It then calls the various activities needed. You then have the code for each activity separately encapsulated to that activity, with potentially some classes specific to that activity to reduce complexity.
 

RichardN

Active Member
Licensed User
@DawningTruth... You are spot on.

Simple is good. Handle the [Back] key presses in the right order and you have yourself a workable page stack (almost at simple as iOS)
:)

This approach should work where you don't need multiple branching of sub pages. IE where you leave the main page to begin down the road of several logical paths before you retrace your steps either page by page or directly. For example

Menu
1..2a...3a...4a
1..2b..3b..4b
1..2c..3c..4c
 
Last edited:

John Horlock

Member
Licensed User
Ok - Well i'm truly lost... I'm so used to a MVC concept and the idea that the layout files are bound to the Activities is just bugging me...

I like the B4XDrawer as its supposed to be iOS compatible - and if the app makes it that far it will be on both Android and iOS...
But i'm still not getting to the point where i can have a working empty framework .

Simple layout idea is
Login page - Single Activity + Layout
Main / Dashboard - This is an Activity with the side menu.
All Other pages need to be Activities + Layout - BUT with the Menu as well

BUT i don;t want to have to code the menu on every page - i Want to just include it as a class and have the button click correspond to the code in the CLASS.
Seen i can only have ONE Activity running at a time..

How is this possible - I'm sure i must be missing something... but at the moment its really looking a step backwards from my current language sets
 

DawningTruth

Active Member
Licensed User
Ok - Well i'm truly lost... I'm so used to a MVC concept and the idea that the layout files are bound to the Activities is just bugging me...

I like the B4XDrawer as its supposed to be iOS compatible - and if the app makes it that far it will be on both Android and iOS...
But i'm still not getting to the point where i can have a working empty framework .

Simple layout idea is
Login page - Single Activity + Layout
Main / Dashboard - This is an Activity with the side menu.
All Other pages need to be Activities + Layout - BUT with the Menu as well

BUT i don;t want to have to code the menu on every page - i Want to just include it as a class and have the button click correspond to the code in the CLASS.
Seen i can only have ONE Activity running at a time..

How is this possible - I'm sure i must be missing something... but at the moment its really looking a step backwards from my current language sets
There is only a minor misunderstanding on your part. You almost got it :).

Think of the Activities as you would a WebPage in ASP or PHP. Each webpage page has a display component and processing components i.e. A picture and functions.

You then add elements programmatically to each webpage page. So you programmatically add a menu, header footer, content area etc... You obviously define the menu in a single place and then add it to each web page as required.

That is the basic concept of a B4x and in fact Android Activities.

So to answer your question:

Login page - Single Activity + Layout
Main Activity - Kicks off the other activities
All Other pages need to be Activities + Layout - BUT with the Menu as well
Layout - Menu which is added to each activity programmatically.

I found that once I actually started working with B4A a lot of the confusion was resolved, in terms of how to architect the application. So my suggested path forward is as follows:

1. If you have not done so yet, go through Erel's excellent video tutorials: https://www.b4x.com/etp.html
2. Visit this thread: https://www.b4x.com/android/forum/threads/b4x-b4xdrawer-sliding-drawer.97828/
Look at the code and go through the examples.
3. Create the above proposed layout. With a couple of dummy pages. Play with different views and layouts to get a feel for how everything works together. Program a few buttons.
4. Create a mini fun project, nothing too serious. But something that forces you to use the different views, activities, layouts etc...
5. Post the dummy project when done for crit.

I think that way you will develop the intuitive feel you need, before architecting your major app. You will make the learning mistakes early on, so you avoid them when it really counts.

How does that approach sound to you?
 
Last edited:
Top