I am writing an app that has 3 editext, I want to call a calculator (tapecalc) from a menu button and bring the result from the calculator to the edittext that was with the focus when the calculator menu button was clicked. I'm doing this but is not working.
B4X:
Sub Globals
Dim txtN As EditText
Dim txtD As EditText
Dim txtI As EditText
Dim Send As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
txtN.Initialize("edText")
txtD.Initialize("edText")
txtI.Initialize("edText")
'
txtN.RequestFocus
End Sub
Sub Activity_Resume
'Msgbox(TapeCalc.Resultado,"Resultado")
If Sender = Null Then
Msgbox("Nulo","Sender")
Else
Msgbox(Send,"Sender")
Send.Text = TapeCalc.Resultado
End If
End Sub
Sub edText_FocusChanged (HasFocus As Boolean)
Send = Sender
End Sub
Resultado is declared in Sub Process_Globals from tapecalc activity.
Just write a function for the calculator. Let's assume the calculater is a function in a Code Module:
CodeModule Calculator:
B4X:
Sub calc(a as int, b as int, c as int)
Return a * 2 / b + c
End Sub
In your Activity, just call the function:
Dim result as int : result = Calculator.code(1,2,3) ' or here you can use your variables
EditText1.Text = result
Se non ho capito vero, scrivi piu information di cosa vuoi fare.
In case I haven't understood, write more information about what you want to achieve.
The calculator is an activity that is called form a menu button (see "Tape Calc" in the "Basic4android Share Your Creations" forum). I can call it and the result is back in the main activity, I only can't put it in the text property of the edittext that was with focus when the calculator was called.
I need to test sender because in the first time this acticvity is opened the sender is null and send too. If I don't do this I receive an error message.
Sub Process_Globals
Dim edtIndex As Int : edtIndex = -1
End Sub
Sub Globals
Dim edText(3) As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
For i = 0 To 2
edText(i).Initialize("edText")
edText(i).Tag = i
Next
edText(0).RequestFocus
End Sub
Sub Activity_Resume
If edtIndex < 0 Then
edText(edtIndex).Text = ""
Else
edText(edtIndex).Text = TapeCalc.Resultado
End If
End Sub
Sub edText_FocusChanged (HasFocus As Boolean)
Dim Send As EditText
Send = Sender
edtIndex = Send.Tag
End Sub