Android Question CustomLayoutDialog in Loop

mw71

Active Member
Licensed User
Longtime User
Hi,

i use the follow Code:
B4X:
Do While rbtn_check < 2
            rbtn_check=0

            Dim sf As Object = cld.ShowAsync("Export","","Start"),"Cancle",Null,False)
            cld.SetSize(90%x,hoehe + 150dip)
            Wait For (sf) Dialog_Ready (DialogPanel As Panel)

            DialogPanel.AddView(pnl, 0, 0, DialogPanel.Width, DialogPanel.Height)    'pnl is a Panel
            Wait For (sf) Dialog_Result (ret As Int)

            If ret=DialogResponse.NEGATIVE Then Exit

            If rbtn_port_ja.Checked=True Or rbtn_port_nein.Checked=True Then rbtn_check=1
            If rbtn_ref_ja.Checked=True Or rbtn_ref_nein.Checked=True Then rbtn_check=rbtn_check+1
            If rbtn_check<2 Then
                MsgboxAsync(Starter.loc.Localize("txt_GMA_Exp_AU"), Starter.loc.Localize("txt_GMA_Exp_AU"))
                wait for Msgbox_result (r As Int)
            End If
        Loop

- Start (First Run) is all o.k.
- if User dont select a Radiobutton (rbtn....checked) and Click on Start the Loop run a second (while rbtn_check <2)
- on this Point the Code Crash (at DialogPanel.AddView(pnl.......)

thanks for help
 

mw71

Active Member
Licensed User
Longtime User
it means i must call RemoveView(), (child has parrent??)

copy of Log follows (in a few hours), currently no acess to PC
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
at this Line:
DialogPanel.AddView(pnl, 0, 0, DialogPanel.Width, DialogPanel.Height)

Error occurred on line: 6947 (Main)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4277)
at android.view.ViewGroup.addView(ViewGroup.java:4127)
at android.view.ViewGroup.addView(ViewGroup.java:4099)
at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:65)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.agraham.dialogs.InputDialog$ExtendedBALayout$1.run(InputDialog.java:2467)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
java.lang.RuntimeException: java.net.SocketException: sendto failed: EBADF (Bad file number)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:170)
at anywheresoftware.b4a.ShellBA$1.run(ShellBA.java:74)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.net.SocketException: sendto failed: EBADF (Bad file number)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:546)
at libcore.io.IoBridge.sendto(IoBridge.java:515)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266)
at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
at anywheresoftware.b4a.shell.ShellConnector.sendControlMessage(ShellConnector.java:62)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:297)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
... 9 more
Caused by: android.system.ErrnoException: sendto failed: EBADF (Bad file number)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:206)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
at libcore.io.IoBridge.sendto(IoBridge.java:513)
... 20 more
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
DialogPanel.AddView(pnl, 0, 0, DialogPanel.Width, DialogPanel.Height) 'pnl is a Panel
Add a
B4X:
pnl.RemoveView
after this line

But it looks like you are adding the same panel each time. Maybe this is the issue.
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
Add a
B4X:
pnl.RemoveView
after this line
it works not correct. No abort, but the Pnl is not show.
I will test a other place.

EDIT: before Loop it Works in Test Projekt

But it looks like you are adding the same panel each time. Maybe this is the issue.
Yes, i do that.
is there a better solution??

There 4 Radiobuttons in 2 Groups. Each Grupe must have a selection (Rbtn 1 or 2)
 
Last edited:
Upvote 0

mw71

Active Member
Licensed User
Longtime User
The panel / layout is code generated

I added a small project for testing.
With (comment) old it works.
Test to add elements to DialogPanel does not work (I think it's also a "Panel" problem)

rbtn_ref_ja and rbtn_ref_nein are one group.
colored_port_ja and colored_port_no are the other group.
In each group, 1 button (Yes or No) must be selected.
 

Attachments

  • Test.zip
    9.6 KB · Views: 146
Upvote 0
Top