Many different EditTexts in ScrollViews

U

unba1300

Guest
Hi.
I'm trying not to ask questions here every time I get stuck, but I've been working on this for several days now and could use some help.
I'm writing an app that will have several layouts, each having several edittexts for data entry, but each layout will have a different number of edittexts. I had it all working fine with a layout that only had five edittexts because I made them a view array and was able to reference them that way, but with a longer list, I'm adding the edittexts with code to a scrollview, but then they all have the same name; although I do give each one a different tag in a loop. So now when I load this layout I haven't been able to figure out how to populate the edittexts from my list file. Something like this in a loop:
B4X:
etName.Text = lstNames.Get(i)
does not work since several edittexts are called etName. I think dealing with both tags and view arrays for the same problem has left me confused. Maybe there's a better approach? Thanks for any help.
 

klaus

Expert
Licensed User
Longtime User
How did you add the EditText views to the ScrollView ?
Do you have other views on the ScrollView or only the EditText views ?
You can get view references with ScrollView.Panel.GetView(Index).
The view indexes begin from 0 and are increased by one each time a new view is addded.
If you have only the EditText views on the ScrollView then the first EditText has index 0 the second index 1 and so on.
If you have for example for each item a Label plus an EditText then the first Label has index 0 the first EditText index 1 the second Label index 2 the second EditText index 3 and so on. The Label indexes are Item * 2 and the EditText indexes are Item * 2 + 1.

Best regards.


Best regards.
 
Upvote 0
U

unba1300

Guest
Thank you Klaus. I'm making progress.
EditTexts are the only views in the ScrollView. I now have them populating with values from a list, but when I change the values and click a save button, values like this are saved instead of what I entered: android.widget.EditText@43e8bd58
Of course that's because of this code:
B4X:
etName.Text = svNames.Panel.GetView(i)
lstNames.Add(etName.Text)
There is no GetView.Text, so I haven't gotten it yet. And I bet it's so simple.
 
Upvote 0
U

unba1300

Guest
I think I got it. I declared another variable as an EditText.


Saving...
B4X:
For i = 0 To 9
  et = svTraits.Panel.GetView(i)
  If et.Text <> "" Then
    lstTraits.Add(et.text)
  End If
Next
Reading...
B4X:
For i = 0 To 9
  Dim etTrait As EditText
  etTrait.Initialize("etTrait")
  svTraits.Panel.AddView(etTrait,5%x, 5dip+i*50dip, 95%x-5%x, 40dip)
  If i < lstTraits.Size Then
    etTrait.Text = lstTraits.Get(i)
  End If
Next
 
Upvote 0

ckoehn

Banned
You could use "Sender" as well. "Sender" is the object that called the sub. Read up on it. :)

Sender.Text = lstNames.Get(i)

Later,
Clint
 
Upvote 0
Top