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 ?
 

Lello1964

Well-Known Member
Licensed User
Longtime User
Create a sub in the Activity Module that will do the updates. Then when running your service use CallSub with update data and your texts will be updated.

i know that, but i have many edit text to update.

How pass edittext object and next edit text to main module ?

for example

callsub3(main,"UpdateEditText","EditText01","Newtext")

?
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Follow this code:

In your service, create an array with the EditText values, and pass the array as a parameter to your sub:

 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
Follow this code:

In your service, create an array with the EditText values, and pass the array as a parameter to your sub:


I can't use array, i have more edit text.

must pass object name and value.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Well, you can have an array of view (edittext) in your main module, and you can pass an array of values from you sub, as explained.
Then, in you main sub, go through the array of edittext assigning the same position of the array of values
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
Well, you can have an array of view (edittext) in your main module, and you can pass an array of values from you sub, as explained.
Then, in you main sub, go through the array of edittext assigning the same position of the array of values

Sorry, but i can't use array

B4X:
dim EdiTextdddfd01 as EditText
dim EdiTex4545t02 as EditText
dim EdiTex454t03 as EditText
dim EdiTex4545t04 as EditText

this is an example
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Probably will be better solutions, but without knowing anything about your code.

Maybe this can help
 

Attachments

  • array.zip
    9.6 KB · Views: 139
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
Probably will be better solutions, but without knowing anything about your code.

Maybe this can help

Thank for your help, but this solution don't solve my problem.

I must change 1 editext at a time, and can't insert name in array.

I'm looking for a solution to pass object name and value to a sub

like :
B4X:
callsub3(main,"UpdateEditText","EditText01","Newtext")

where
EditText01 is the object name in Main activity : for example : EdiText01
Newtext is the new text

i don't know is there is a solution.
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
You have a problem as you can't refer to a view by name in this situation.
If you are willing to use the edittext/ label tags then you could try the attached, modified from Jose's example. It's not very elegant and could be slow dependant on the number of views you have!
 

Attachments

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

Lello1964

Well-Known Member
Licensed User
Longtime User
You have a problem as you can't refer to a view by name in this situation.
If you are willing to use the edittext/ label tags then you could try the attached, modified from Jose's example. It's not very elegant and could be slow dependant on the number of views you have!
Thank for you help, but this isn't solution i'm looking for.

Raffaele
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Baffled as to what you are looking for then!!
I thought you wanted to be able to set the text on an individual edittext/ label?
What is it you want to do?
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
Baffled as to what you are looking for then!!
I thought you wanted to be able to set the text on an individual edittext/ label?
What is it you want to do?
this :
callsub3(main,"UpdateEditText","EditText01","Newtext")

where
EditText01 is the object name in Main activity : for example : EdiText01
Newtext is the new text

I know that i can pass a tag or flag to a sub, but i want know is there is a way to pass editetext name as object, i can add any new edittext to main without add new tag. or id.

Sorry is i'm not clear, my english isn't good.
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
I guess you could have a sub for each view:
B4X:
sub UpdateEditText01(TXT as string)
   edittext01.text = txt
end sub
sub UpdateEditText02(TXT as string)

etc.
but that could be a lot of subs.

Or you could select the edittext:
B4X:
sub UpdateEditText(ET as string, TXT as string)
   select case ET
       case "EditText01"
            edittext01.txt = TXT
       case "EditText02"
etc.
but again possible lots of 'cases'
The real problem is that you can't refer to the view by name. That would make lots of things easier!!
 
Last edited:
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I don't know if I understood your need.
Check this.


*** EDIT ***
Removed example. It was a Class, not a Service.
 
Last edited:
Upvote 0
Top