Android Question Auto Change text

Yazh

New Member
can text box auto change value? like picture below?
i used code

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

End Sub
Private Sub label1_FocusChanged(Hasfocus As Boolean)
Label3.text = Label1 * Label2
'Label3.Text= NumberFormat(Label3.Text,0,0) '< Is this true code for number format?
End Sub

but didn't work, i need like vb code
Private Sub label1_change()
.................
end sub

one more, if i use code
Label2 or label1 format Label1.Text= NumberFormat(Label1.Text,0,0)
label3.text can't get value My apps came out straight away

can tell me the code

sorry about my english

tanya.gif
 

ronell

Well-Known Member
Licensed User
Longtime User
you need textbox to input value then use the text_changed event

try the sample project
 

Attachments

  • test.zip
    8 KB · Views: 219
Last edited:
Upvote 0

Yazh

New Member
Thanks Ronell i change your project like this
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

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.

   
    Private EditText1 As EditText
    Private EditText2 As EditText
    Private EditText3 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("test")
    'EditText1.Text= 0
    'EditText2.Text= 0
    'EditText3.Text= 0
    'Dim x As Double
    'x = EditText1.Text
   ' x = NumberFormat(x,0,0)
End Sub

Private Sub EditText1_TextChanged (Old As String, new As String)
If EditText1.Text.Length= 0 Then
    EditText1.Text= "0"
    Else
        Result
End If

End Sub

Private Sub EditText2_TextChanged (Old As String, new As String)
If EditText1.Text.Length= 0 Then
    EditText2.Text= "0"
    Else
        Result
End If
End Sub

Private Sub EditText3_TextChanged (Old As String, new As String)
If EditText1.Text.Length= 0 Then
    EditText1.Text= "0"
End If
End Sub

Sub Result()
Dim Num1 As Int
Dim Num2 As Int
Num1 = EditText1.Text
Num2 = EditText2.Text
EditText3.Text =Num1 +Num2
End Sub

Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
if i change EditText1 my app close so i creat
EditText1.Text= 0
EditText2.Text= 0
EditText3.Text= 0
at Sub Activity_Create, It just works for EditText1 if EditText2 type number app close, and i don't need 0(Zero) at first textbox


Sorry i'm newbie
 

Attachments

  • tanya.zip
    362.7 KB · Views: 189
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
see your _textchanged event why the app is closing ,
and i don't need 0(Zero) at first textbox
you need to declare a number so that the app will know that the edittext is a number input type, thats the reason why i add a condition a default 0 value for edittext everytime its length is 0 or else it will become a string value.
 

Attachments

  • fix.zip
    8 KB · Views: 203
Upvote 0
Top