Android Question How change editText.text value from service module

Lello1964

Well-Known Member
Licensed User
Longtime User
I have more edittext in main module:

Main module :

B4X:
dim EdiText01 as EditText
dim EdiText02 as EditText
dim EdiText03 as EditText
dim EdiText04 as EditText
' etc...
EdiText01.text = " text1"
EdiText02.text = " text2"
EdiText03.text = " text3"
EdiText04.text = " text4"

I must change text value from other Class Module

My Module :

B4X:
EdiText01.text = " Newtext1"
EdiText02.text = " Newtext2"
EdiText03.text = "New text3"
EdiText04.text = " Newtext4"

This code cannot work, but how can i do it ?
 

RJB

Active Member
Licensed User
Longtime User
Sorry I posted that before it was finished, I've updated it above.
Using tags was the conclusion I came to with a similar problem. Not really satisfactory as I wanted to use the tags for something else, but it works!
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Using a Map provides a way to avoid using tags and is a bit more elegant and probably quicker. See the attached example.
 

Attachments

  • array.zip
    9.8 KB · Views: 161
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
You could pass the array of text boxes to the class that is doing the updating.

B4X:
Sub Activity__Create (Firstime as Boolean)
    Dim OtherClass1 As OtherClass

    Dim EdiText01 As EditText: EdiText01.Initialize("")
    Dim EdiText02 As EditText: EdiText02.Initialize("")
    Dim EdiText03 As EditText: EdiText03.Initialize("")
    Dim EdiText04 As EditText: EdiText04.Initialize("")

    EdiText01.text = " text1"
    EdiText02.text = " text2"
    EdiText03.text = " text3"
    EdiText04.text = " text4"
    
    Dim ed() As EditText = Array As Object(EdiText01, EdiText02, EdiText03, EdiText04)
    OtherClass1.Initialize(Activity, ed)
End Sub

B4X:
Public Sub Initialize(Parent As B4XView, ed() As Object)
    Dim xed As B4XView = ed(2)        'you must cast this to B4View for it to work
    xed.text = "newText"
    For i = 0 To 3
        Dim xed As B4XView = ed(i)
        Log(xed.text)
    Next
End Sub
 
Upvote 0
Top