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?
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.
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.
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