Android Question [B4X] B4XGifView Adding view from code (SOLVED)

walterf25

Expert
Licensed User
Longtime User
Is there a way to add the B4XGifView not from the designer but from code, I just tried it and i get the following error:
** Activity (shoeheight) Pause, UserClosed = false **
** Activity (picturescreen) Create, isFirst = true **
Error occurred on line: 183 (PictureScreen)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at com.strom.ergonomics2.picturescreen._gengifview(picturescreen.java:676)
at com.strom.ergonomics2.picturescreen._activity_create(picturescreen.java:521)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at com.strom.ergonomics2.picturescreen.afterFirstLayout(picturescreen.java:105)
at com.strom.ergonomics2.picturescreen.access$000(picturescreen.java:17)
at com.strom.ergonomics2.picturescreen$WaitForLayout.run(picturescreen.java:83)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
** Activity (picturescreen) Resume **

This is how I am initializing the view:
B4X:
    Dim gif As B4XGifView
    Dim pnl As B4XView = xui.CreatePanel("")
    gif.Initialize(Me, "gif")
    pnl.SetLayoutAnimated(0,0,0, pnlCamera.Width, pnlCamera.Height/2)
    pnl.AddView(gif.mBase, 0, 0, pnl.Width, pnl.Height)
    gif.SetGif(File.DirAssets, gifName)
    Return pnl

I don't have time to look at the source code, but i guess i'll have to make time and see what's going on, I thought it would just work.

Walter
 

walterf25

Expert
Licensed User
Longtime User
Never mind, solved it,

B4X:
    Dim gif As B4XGifView
    Dim lbl As Label
    Dim m As Map
    lbl.Initialize("")
    m.Initialize
    Dim pnl As B4XView = xui.CreatePanel("")
    gif.Initialize(Me, "gif")
    pnl.SetLayoutAnimated(0,0,0, pnlCamera.Width, pnlCamera.Height/2)
    gif.DesignerCreateView(pnl, lbl, m)
    '''pnl.AddView(gif.GifDrawable, 0, 0, pnl.Width, pnl.Height)
    gif.SetGif(File.DirAssets, gifName)
    Return pnl
 
Upvote 0
Top