Is there a way to iterate through the Controls/Views?

FrankR

Member
Licensed User
Longtime User
Without knowing their names, is there a way to iterate through all the
controls/view of an Activity?
 

specci48

Well-Known Member
Licensed User
Longtime User
Yes!

This is an example from Erel hiding all buttons of an activity:

B4X:
For i = 0 To Activity.NumberOfViews - 1
   If Activity.GetView(i) Is Button Then 
       Activity.GetView(i).Visible = False
   End If 
Next


specci48
 
Upvote 0

luthepa1

Member
Licensed User
Longtime User
Yes!

This is an example from Erel hiding all buttons of an activity:

B4X:
For i = 0 To Activity.NumberOfViews - 1
   If Activity.GetView(i) Is Button Then 
       Activity.GetView(i).Visible = False
   End If 
Next


specci48

So using this example how would I modify it for getting or setting the check state for a number of Checkbox views on a panel view?

I have seen threads on how to trigger code for a "Sender" event but what I am trying to do is iterate through all checkbox views on a panel when I call my sub routine to set or get the checked status for persistent data for the pause and resume events on screen rotation.

In designer I have added a number to the views tag property when I iterate through all views of a panel. Below is the code I have at the moment but I am thinking I should not have to use a Select Case statement with direct reference to the checkbox view name. I was hoping to do something like
B4X:
MyCheckStatus = Activity.GetView(i).Checked
but "checked" is not a property when using GetView(i)

I am having a mind blank! Can anyone help me please?

B4X:
      For i = 0 To pnlCreateWorkout.NumberOfViews -1
         If pnlCreateWorkout.GetView(i) Is CheckBox OR EditText Then
            Tag = pnlCreateWorkout.GetView(i).Tag
            Select Tag
               Case 1
                  'CheckBox All Days
                  MyPersistantData.cbstate(Tag) = 
               Case 2
                  'Checkbox Sunday
               Case 3
                  'Checkbox Monday
               Case 4
                  'Checkbox Tuesday
               Case 5
                  'Checkbox Wednesday
               Case 6
                  'Checkbox Thursday
               Case 7
                  'Checkbox Friday
               Case 8
                  'Checkbox Saturday
               Case 9
                  'EditText Workout Title
               Case 10
                  'Spinner - Difficulty Level Selector
               Case 11
                  'TextEdit Discription
               Case 12
                  'TextEdit All Days Title
               Case 13
                  'TextEdit Sunday Title
               Case 14
                  'TextEdit Monday title
               Case 15
                  'TextEdit Tuesday Title
               Case 16
                  'TextEdit Wednesday Title
               Case 17
                  'TextEdit Thursday Title
               Case 18
                  'TextEdit Friday Title
               Case 19
                  'TextEdit Saturday Title
            End Select
         End If
      Next
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Check in the Statemanager Module, you will find the solution for most controls.
http://www.b4x.com/forum/basic4andr...id-applications-settings-state.html#post54161

You could use something like this:
B4X:
For i = 0 To Activity.NumberOfViews - 1
      If Activity.GetView(i) Is CheckBox Then
         Dim Check As CheckBox 
         Dim isChecked As Object 
         Check = Activity.GetView(i)
         isChecked = Array As Object(Check.Checked)
      End If
   Next

Rolf
 
Upvote 0

luthepa1

Member
Licensed User
Longtime User
Thanks guys!!!

Ah, this keeps on getting better this Basic 4 Android environment! Absolutely love it! And the online community is fantastic!

StateManager looks like the way to go but also thank you rbsoft for the added code solution to my issue. Even if I use StateManager what I was coding would still be on my mind until I find the solution. At least tonight when I go to bed I will be able to switch my brain off and not think about coding - lol!
 
Upvote 0
Top