Android Question [B4X] Check view IsNot B4XView or any other type

Alexander Stolte

Expert
Licensed User
Longtime User
So I can check whether something is a certain type:
B4X:
If View Is B4XView Then
but i have often had situations where i have to check whether it is not a certain type, e.g:
B4X:
If xtf_TextBox.IsInitialized = False Or xtf_TextBox.Parent Is Not B4XView Or xtf_TextBox.Parent.IsInitialized = False Then Return

I can also write a function that looks like this, but that is not a nice solution at all:
B4X:
Private Sub IsObjectB4XView(View As Object) As Boolean
    Return View Is B4XView
End Sub

Does the ide have a syntax to achieve this goal?
 
Solution
Unless I don't understand your question you can use the Not() method
NOTE that testP is both a Label and a B4XView! Something I just learned.
And lbl is both too!

B4X:
    Dim lbl As Label
    lbl.Initialize("")
    Dim testP As B4XView = lbl

    Log(testP Is B4XView)    'true
    Log(testP Is Label)        'true

    Log(Not(testP Is B4XView))    'false
    Log(Not(testP Is Label))    'false
    
    Log(lbl Is B4XView)        'true
    Log(lbl Is Label)        'true
    
    Log(GetType(testP))        'javafx.scene.control.Label
    Log(GetType(lbl))        'javafx.scene.control.Label

William Lancee

Well-Known Member
Licensed User
Longtime User
Unless I don't understand your question you can use the Not() method
NOTE that testP is both a Label and a B4XView! Something I just learned.
And lbl is both too!

B4X:
    Dim lbl As Label
    lbl.Initialize("")
    Dim testP As B4XView = lbl

    Log(testP Is B4XView)    'true
    Log(testP Is Label)        'true

    Log(Not(testP Is B4XView))    'false
    Log(Not(testP Is Label))    'false
    
    Log(lbl Is B4XView)        'true
    Log(lbl Is Label)        'true
    
    Log(GetType(testP))        'javafx.scene.control.Label
    Log(GetType(lbl))        'javafx.scene.control.Label
 
Last edited:
Upvote 0
Solution
Top