hey all,
if i rotate the device it resets everything to start, i experimented with a few things but iam coming nowhere.
can someone push me in the right direction? this is btw code from the tutorial guess, but with my own tests.
if i rotate the device it resets everything to start, i experimented with a few things but iam coming nowhere.
can someone push me in the right direction? this is btw code from the tutorial guess, but with my own tests.
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type StateType(lab1 As String, lab4 As Int, lab6 As Int, lab7 As String, edit1 As Int, nmbr As Int, att As Int, lnr As Int)
Dim State As StateType
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim MyNumber As Int
Dim EditText1 As EditText 'will hold a reference to the view added by the designer
Dim Label1 As Label
Dim Label4 As Label
Dim Label6 As Label
Dim Label7 As Label
Dim attempt As Int
Dim lastnr As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1") 'Load the layout file.
MyNumber = Rnd(1, 100) 'Choose a random number between 1 to 99
attempt = 0
lastnr = 0
Label7.Text = ""
Label4.Text = ""
Label6.Text = ""
Label1.Text = ""
EditText1.Text = ""
End Sub
Sub Button1_Click
If EditText1.Text > MyNumber Then
Label1.Text = "Lower"
Else If EditText1.Text < MyNumber Then
Label1.Text = "Higher"
Else
Label7.Text = "yay! you did it!"
Label1.Text = ""
End If
EditText1.SelectAll
attempt = attempt + 1
Label4.Text = attempt 'aantal attempts
Label6.Text = EditText1.Text 'last nr weergave
End Sub
Sub Button2_Click 'reset alles, alles naar beginwaardes inc new raad getal
attempt = 0
lastnr = 0
MyNumber = Rnd(1, 100)
Label7.Text = ""
Label4.Text = ""
Label6.Text = ""
Label1.Text = ""
EditText1.Text = ""
End Sub
Sub ResetState
State.edit1 = ""
State.lab1 = ""
State.lab4 = ""
State.lab6 = ""
State.lab7 = ""
End Sub
Sub Activity_Resume
'dit gaat goed?
attempt = State.att
lastnr = State.lnr
MyNumber = State.nmbr
'hier gaat het fout...
' Label7.Text = State.lab7
' Label4.Text = State.lab4 'attempts
' Label6.Text = State.lab6
' Label1.Text = State.lab1
' EditText1.Text = State.edit1
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'test
If UserClosed Then
ResetState
Else
State.lab7 = Label7.Text
State.lab4 = Label4.Text
State.lab6 = Label6.Text
State.lab1 = Label1.Text
State.edit1 = EditText1.Text
State.nmbr = MyNumber
End If
End Sub