Android Question Cast Object to View

Indy

Active Member
Licensed User
Longtime User
Hi Folks,

Quick question - Is it possible to cast a generic Object to a View? I want to convert a generic object to a view which is based on a value from a database table. For example;

B4X:
Dim ob As Object
Dim cbox as CheckBox


if val="cb" then
    ob = cbox
    ob.Initialize("")
    
    etc....
end if

The reason I'm doing this is because I'm building a config screen, which will read values from a table in an SQlite database and dynamically create views and set their values. I'd prefer not to hardcode the views as these may change over time.

Thanks
 

Indy

Active Member
Licensed User
Longtime User
You could use a B4XView instead of an object.

B4X:
Dim MyView As B4XView



if val="cb" then
    Dim cbox as CheckBox
    cbox.Inizialize("") ' <--- "cbox"?
    MyView = cbox
  
    etc....
end if

You Sir have saved the day - Worked like a charm. Thank you for your help.
 
Upvote 0
Top