Android Question My Toggle Button Library - rotation issue [Solved]

msali

Member
Licensed User
Longtime User
Hi,
Following what I read at the link:
(https://www.b4x.com/android/forum/threads/customfloatingmenubutton-b4a-library-source-code.85485/)

I started creating my own library (first attempt) for a bigger project that i am planning for.

It is basically a toggle button library as shown in attached image tgbLR.png but will grow and get further customized as per my project's need (with time).

So far all is working fine.

Problem:
But the problem is when i rotate the phone. then the application crashes.

I have attached an example usage code and the library too.

would appreciate your help.

many thanks in advance.
 

Attachments

  • ToggleButtonsLib_v1.1.zip
    6.4 KB · Views: 249
  • tgbLR_Fruits.png
    tgbLR_Fruits.png
    70.5 KB · Views: 515
  • ToggleButtonExample_2.zip
    9.8 KB · Views: 259
Last edited:

msali

Member
Licensed User
Longtime User
It is better to post the solution so this thread can help others...
Solution was as follows:


Step 1:
Declared a MAP variable Sub Process_Globals

B4X:
    Private mapState As Map

Step 2:
Save the state in Sub Activity_Pause

B4X:
Sub Activity_Pause (UserClosed As Boolean)
    mapState.Put("LR", tgbLR.GetCurrentButtonName)
    mapState.Put("Fruits", tgbFrutis.GetCurrentButtonName)
End Sub


Step 3:
In Sub Activity_Create, initialize the mapState if FirstTime was True or Get & Set the State if False

B4X:
    If FirstTime = False Then
        tgbLR.SetSelectedButton(mapState.Get("LR"))
        tgbFrutis.SetSelectedButton(mapState.Get("Fruits"))
    Else
        mapState.Initialize
    End If

I have updated the modified example "ToggleButtonExample_2.zip" in the first post.
 
Last edited:
Upvote 0
Top