Android Question Text From Dynamically Created EditText

Sreenadh OG

Member
Licensed User
Hai,

I have a Button to add EditText dynamically, now I want to get text from all created EditText.
My code is given below..
B4X:
'Dim i as Int
'i=80
'Dim txt as EditText
Sub BtnAdd_Click
    txt.Initialize("")
    Activity.AddView(txt,10,i,40,30) 
    i=i+30
End Sub
Sub btnnew_Click
    Dim str As String
    str=txt.Text ' here i want to get all text as array
End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Use a global list (or map) to store all created EditText-objects
You then can use this list, to get all texts from the edits stored in this list...

B4X:
' in globals
dim editlist as list

' in activity create
editlist.initialize
B4X:
Sub BtnAdd_Click
   dim txt as EditText
    txt.Initialize("txt")
    Activity.AddView(txt,10,i,40,30) 
   editlist.add(txt)
    i=i+30
End Sub
B4X:
Sub btnnew_Click
For Each txt As EditText In editlist
    ' get the text from edit here
    Dim content As String = txt.Text
Next
End Sub
 

Sreenadh OG

Member
Licensed User
hai,
I want to delete Dynamically created EditText on Button_click, How can i delete each EditText for each Button_click
 

DonManfred

Expert
Licensed User
have a look at
B4X:
Activity.RemoveViewAt
. Your need to find out which position your view ihas n the list of all Activity-views first.
Set a special TAG to the edittexts and have a look at
B4X:
for Each v As View In Activity.GetAllViewsRecursive 
Next
too
 
Top