B4J Question Form Navigation with Back Button

floatingpoint

Member
Licensed User
Longtime User
Searched around but unable to find a solution.
I would like to have a 'back' button on B4J so that form navigation is easier.

I have tried:
B4X:
Public Sub LoadSpacesForm(callback_module As Object,callback_function As String)
   cMod = callback_module
   cFun = callback_function
   If frm.IsInitialized = False Then
       frm.Initialize("frm", 550, 600)
       frm.RootPane.LoadLayout("SpacesForm")
   End If
   frm.Show
   FillList2
End Sub
and
B4X:
Sub btnFavourites_Action
   CLVSpaces.Clear
   frm.Close
   FavouritesForm.LoadFavouritesForm(Me,"LoadSpacesForm")
End Sub
on the first form then
B4X:
Public Sub LoadFavouritesForm(callback_module As Object,callback_function As String)
   cMod = callback_module
   cFun = callback_function
   If frm.IsInitialized = False Then
       frm.Initialize("frm", 550, 600)
       frm.RootPane.LoadLayout("FavouritesForm")
   End If
   frm.Show
   FillList2
End Sub
and
B4X:
Sub btnBack_Action
   CLVFavourites.Clear
   frm.Close
   CallSub(cMod,cFun)
End Sub
on the second form.
However clicking the back button on the second form results in:
B4X:
An error occurred:
(Line: 0) End Sub
java.lang.Exception: Sub loadspacesform signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject b4j.example.spacesform_subs_0._loadspacesform(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception
No parameters

What is the preferred way to implement a back button in B4J?
 

Daestrum

Expert
Licensed User
Longtime User
Small example of what I use
(example is really cut down but shows how to use a stack for the forms)
 

Attachments

  • backbutton.zip
    1.7 KB · Views: 212
Upvote 0

floatingpoint

Member
Licensed User
Longtime User
You need to better define the interface. Do you want to hide the current form when you show a new form? So there is always a single form visible?

Yes, close form and clear custom list view, I only want a single form to show.
Really just want to remember which form was opened prior to current form and open it using a back button.

Small example of what I use
(example is really cut down but shows how to use a stack for the forms)

Thank you, this may be a solution.
However my forms require custom list view to be filled on opening and cleared on closing.
It is not clear to me how this extra processing can be introduced into this push/ pop stack arrangement.
 
Upvote 0

floatingpoint

Member
Licensed User
Longtime User
I found a solution using a simple list:
B4X:
    Public backForm As List
...

Sub LoadLastForm
   Dim last As String
   If backForm.Size > 0 Then
       last = backForm.Get(backForm.Size - 1)
       backForm.RemoveAt(backForm.Size - 1)
       Select Case last
           Case "LoginForm"
               LoginForm.LoadLoginForm
           Case "SpacesForm"
               SpacesForm.LoadSpacesForm
           Case "FavouritesForm"
               FavouritesForm.LoadFavouritesForm
       End Select
   End If
End Sub

and
B4X:
Sub btnFavourites_Action
   CLVSpaces.Clear
   frm.Close
   FavouritesForm.LoadFavouritesForm
   Main.backForm.Add("SpacesForm")
End Sub

Sub btnBack_Action
   CLVSpaces.Clear
   frm.Close
   Main.LoadLastForm
End Sub

as appropriate on each form :)
 
Upvote 0
Top