Android Question Set text in Activity views

lymey

Active Member
Licensed User
Longtime User
I would like to scan through the views in an activity and then set/reset the text value of a view depending on the text (or tag value).
The problem is the VIEW type doesn't have a text value that you can read or set as you go through all the views in an activity.

In an older post the following was proprosed by Erel to get the text value:
https://www.b4x.com/android/forum/threads/how-to-get-text-field-of-all-the-view.14925/#post-377675

B4X:
For i = 0 To Activity.NumberOfViews - 1
Dim lbl As Label
IfActivity.GetView(i) Is Label Then
 lbl = Activity.GetView(i)
 Log(lbl.Text)
 End If
Next

Is there a way of setting the text value of a view in a similar way?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use the code from that post. There are better ways now.

B4X:
For Each v As View in Activity.GetAllViewsRecursive
 If v Is Label Then
   Dim lbl As Label = v
   lbl.Text = "Sdf"
 End If
Next

This code will handle the following types: Label, EditText, Button, Checkbox, RadioButton and AutoCompleteEditText. They are all subclasses of Label.
 
Upvote 0

lymey

Active Member
Licensed User
Longtime User
Don't use the code from that post. There are better ways now.

B4X:
For Each v As View in Activity.GetAllViewsRecursive
If v Is Label Then
   Dim lbl As Label = v
   lbl.Text = "Sdf"
End If
Next

This code will handle the following types: Label, EditText, Button, Checkbox, RadioButton and AutoCompleteEditText. They are all subclasses of Label.
Great - works perfectly, thank you!
 
Upvote 0
Top