Android Question Material dialog error

rscheel

Well-Known Member
Licensed User
Longtime User
When I run it for the first time it works fine, but when I run it for the second time, it sends the error

B4X:
Sub Listar_Click
    Builder.Title("Months and Days")
    Builder.Items(Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))
    Builder.ItemsCallback
    Builder.NegativeText("Cancel")
    Builder.Show
End Sub

Sub Dialog_ButtonPressed (Dialog As MaterialDialog, Action As String)
    Select Action
        Case Dialog.ACTION_POSITIVE
            Log("Positive Button pressed")
            ToastMessageShow(Action, False)
        Case Dialog.ACTION_NEGATIVE
            Log("Negative Button pressed")
            ToastMessageShow(Action, False)
        Case Dialog.ACTION_NEUTRAL
            Log("Neutral Button pressed")
            ToastMessageShow(Action, False)
    End Select
   
    Log("CheckBox: " & Dialog.PromptCheckBoxChecked)
End Sub

Sub Dialog_ItemSelected (Dialog As MaterialDialog, Position As Int, Text As String)
    Log($"Item Selected: ${Position} : ${Text}"$)
    ToastMessageShow(Text, False)
End Sub

B4X:
main_listar_click (java line: 607)
java.lang.IllegalArgumentException: LayoutManager android.support.v7.widget.LinearLayoutManager@fa5271c is already attached to a RecyclerView: android.support.v7.widget.RecyclerView{6e45f25 VFED.V... .F....ID 0,0-912,1149 #7f060090 app:id/md_contentRecyclerView}
    at android.support.v7.widget.RecyclerView.setLayoutManager(RecyclerView.java:1182)
    at com.afollestad.materialdialogs.MaterialDialog.invalidateList(MaterialDialog.java:167)
    at com.afollestad.materialdialogs.DialogInit.init(DialogInit.java:367)
    at com.afollestad.materialdialogs.MaterialDialog.<init>(MaterialDialog.java:95)
    at com.afollestad.materialdialogs.MaterialDialog$Builder.build(MaterialDialog.java:2109)
    at com.afollestad.materialdialogs.MaterialDialog$Builder.show(MaterialDialog.java:2114)
    at de.amberhome.materialdialogs.MaterialDialogBuilderWrapper.Show(MaterialDialogBuilderWrapper.java:571)
    at cl.avlchile.avlfinger.main._listar_click(main.java:607)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA$1.run(BA.java:325)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
main_listar_click (java line: 607)
java.lang.IllegalArgumentException: LayoutManager android.support.v7.widget.LinearLayoutManager@fa5271c is already attached to a RecyclerView: android.support.v7.widget.RecyclerView{6e45f25 VFED.V... .F....ID 0,0-912,1149 #7f060090 app:id/md_contentRecyclerView}
    at android.support.v7.widget.RecyclerView.setLayoutManager(RecyclerView.java:1182)
    at com.afollestad.materialdialogs.MaterialDialog.invalidateList(MaterialDialog.java:167)
    at com.afollestad.materialdialogs.DialogInit.init(DialogInit.java:367)
    at com.afollestad.materialdialogs.MaterialDialog.<init>(MaterialDialog.java:95)
    at com.afollestad.materialdialogs.MaterialDialog$Builder.build(MaterialDialog.java:2109)
    at com.afollestad.materialdialogs.MaterialDialog$Builder.show(MaterialDialog.java:2114)
    at de.amberhome.materialdialogs.MaterialDialogBuilderWrapper.Show(MaterialDialogBuilderWrapper.java:571)
    at cl.avlchile.avlfinger.main._listar_click(main.java:607)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA$1.run(BA.java:325)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Any idea of what can be
 

rscheel

Well-Known Member
Licensed User
Longtime User
I already solved it, I was Initializing in Activity_Create, so I moved it to the click event of the button.

B4X:
Sub Listar_Click
    Builder.Initialize("Dialog")
    Builder.Title("Months and Days")
    Builder.Items(Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))
    Builder.ItemsCallback
    Builder.PositiveText("OK")
    Builder.Show
End Sub
 
Upvote 0
Top