Android Question Bug ? (edittext seen as label)

Discussion in 'Android Questions' started by advansis, Jul 26, 2019.

  1. advansis

    advansis Member Licensed User

    Hi guys, I have a problem while checking the type of a view (don't know if previous versions of B4A are affected, mine is 9.30).

    Code:
    Dim T As EditText
        T.Initialize(
    "TXT")
        T.Text=
    "My Text Value"
        
    Activity.AddView(T,10,10,100,100)
       
        
    If T Is Label Then
            
    Log("IS A LABEL")
        
    End If
    The EditText object is recognized as a Label (the LOG says: IS A LABEL) !
    It is a problem when using GetAllViewsRecursive in a panel populated at runtime....
    Is it a bug or inheritance ? If it is inheritance, please tell me how to replicate this feature, sounds interesting...
    OR ELSE: is there any other way for type-checking ?

    Thank you
     
  2. agraham

    agraham Expert Licensed User

    Inheritance!

    Check for type 'EditText' before checking for 'Label'. EditText and Label will both look like a 'View' as well :)
     
    Erel likes this.
  3. ALBRECHT

    ALBRECHT Active Member Licensed User

    Ok, so with IS instead of GetType,

    no way to use the Select case statement ...

    to check the Type of Object ?
     
  4. agraham

    agraham Expert Licensed User

    I don't know, I've never tried. When I need to check a type I use If ... Else If ... End If
     
  5. ALBRECHT

    ALBRECHT Active Member Licensed User

    Thanks, have a good week end.
     
  6. klaus

    klaus Expert Licensed User

    Sure you can!

    Code:
    Sub WhichObject(Obj As Object)
        
    Select True
            
    Case Obj Is EditText
                
    Log("EditText")
            
    Case Obj Is Button
                
    Log("Button")
            
    Case Obj Is Label
                
    Log("Label")
            
    Case Obj Is ListView
                
    Log("ListView")
        
    End Select
    End Sub
     
    Last edited: Jul 27, 2019
    Erel, inakigarm and mangojack like this.
  7. ALBRECHT

    ALBRECHT Active Member Licensed User

    - perfect, it's better for me.

    - in this case also, it s necessary to check the Label at the end, as said Agraham above ?
     
  8. klaus

    klaus Expert Licensed User

    Yes!
     
  9. ALBRECHT

    ALBRECHT Active Member Licensed User

    Thanks for all
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice