Toogle views visibility

tamadon

Active Member
Licensed User
Longtime User
I have the following sub to toggle views visibility

B4X:
Sub ToggleViewVisibility(Mode As Int, Visible As Boolean)
   Dim i As Int
 
    For i=Activity.NumberOfViews-1 To 0 Step -1

      If Activity.GetView(i).Tag = Mode Then
         Activity.GetView(i).Visible = Visible
      End If

    Next
End Sub

But this line "If Activity.GetView(i).Tag = Mode Then" raises an error

LastException java.lang.NullPointerException

Not all views have tag as I only set the tag value on views that I want to toggle the visibility. What am I doing wrong?

Thanks
 

tamadon

Active Member
Licensed User
Longtime User
Encountered another issue, somehow this line

B4X:
 If Activity.GetView(i).Tag <> Null AND Activity.GetView(i).Tag = Mode Then

Never returns true
 
Upvote 0

tamadon

Active Member
Licensed User
Longtime User
On further checking this line

B4X:
Activity.GetView(i).Tag = Mode

Never returns true even though the view tag is equal to the Mode value. Come to think of it, could it be that I am comparing a string Activity.GetView(i).Tag with an Integer?
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Put this message box right before your if statement and see the values it is finding, see if they match:

B4X:
MsgBox(Activity.GetView(i).Tag, Mode)
If Activity.GetView(i).Tag <> Null AND Activity.GetView(i).Tag = Mode Then

or try:

B4X:
If Activity.GetView(i).Tag <> Null AND (Activity.GetView(i).Tag + 0) = Mode Then
 
Last edited:
Upvote 0

tamadon

Active Member
Licensed User
Longtime User
Thanks for the suggestion. Figured out Activity.GetView(i).Tag is a string and I have to set Mode to string too.
 
Upvote 0
Top