Wish expose source view of b4xview

Status
Not open for further replies.

sorex

Expert
Licensed User
Longtime User
Hello,

Would it be possible to have access to the source view that was 'transformed' into a b4x view?

Sometimes you need to set properties to a label or imageview that are not available via B4Xview objects.

an example...

B4X:
dim Lx as b4xview
dim L as label
L.initialize("")
Lx=L

if you want to change click behaviour from somewhere else in the app you need to set L as global variable aswell or add extra arrays/list/maps just to keep track of the source views.

The sub below makes the source easier for B4A but now I see that it won't work for B4i as the userinteraction property ain't available for that object type.

B4X:
Sub enableView(l As B4XView,enabled As Boolean)
#if B4A
l.Enabled=enabled
#else
l.UserInteractionEnabled=enabled
#end if
End Sub


ideal would be to have access to the source view as shown below then you still have direct access to all properties that the source view supports.

B4X:
Sub enableView(l As B4XView,enabled As Boolean)
#if B4A
l.sourceView.Enabled=enabled
#else
l.sourceView.UserInteractionEnabled=enabled
#end if
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
I believe you can do this
B4X:
Dim B4XLabel ad B4XView = NativeLabel
But even so
B4X:
Dim NativeLabel ad Label = B4XLabel

Or use my XUIView library that allows you to access native views
 

sorex

Expert
Licensed User
Longtime User
ok, I didn't think about the fact that it could work the other way aswell.

I'll give that a try.
 

sorex

Expert
Licensed User
Longtime User
thanks for the hint.

The sub below works.

But you need to test on object type first or you'll get object type mismatch errors.

With my proposal this wouldn't be needed as it knows the type already.

But it's a workaround for now and keeping it a 1 liner in the regular source instead of dozens #if B4? checks

B4X:
Sub enableView(l As B4XView,enabled As Boolean)
#if B4A
l.Enabled=enabled
#else
    If l Is Label Then
        Dim lv As Label=l
        lv.UserInteractionEnabled=enabled
    End If
    If l Is ImageView Then
        Dim li As ImageView=l
        li.UserInteractionEnabled=enabled
    End If
#end if
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
Because I thought that if you can do it B4XView = Label / Panel / etc.. has extended the views so they are subject to poliformism and will inherit.

So the opposite also had to work
 
Status
Not open for further replies.
Top