afollestad MaterialDialogs reborn

wimpie3

Well-Known Member
Licensed User
Longtime User
Is there a way to find out the size of the dialog? Might be handy to do some layout calculations on the customView.
 

chefe82

Member
Licensed User
Longtime User
I am just on the tube . How can I evaluate the Buttons

With

B4X:
Sub dialog_onpositive
   
    Log("geht")
End Sub

Error

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Hat das Geät ein Root: false
** Activity (main) Resume **
** Service (firebasemessaging) Create **
** Service (firebasemessaging) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
lib: NOTFOUND 'dialog_onshow
lib:Raising.. dialog_onpositive()lib: NOTFOUND 'dialog_onany
java.lang.Exception: Sub dialog_onpositive signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:171)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
 

DonManfred

Expert
Licensed User
Longtime User
The signature is

B4X:
Sub dialog_onpositive(action As string)
  
    Log("geht")
End Sub
 

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

The following is the code that I used in the version of Afollestad Material Dialogs by tchart
What will be the equivalent code to be used in this version of the Lib ?
B4X:
Sub Globals
  Dim sd1 As MD_SingleChoiceDialog
  Dim nUserChoice As Int
  Dim MenuList As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
  'Default Selected
  nUserChoice = 2

  MenuList.Initialize 
  MenuList.Add("Apple ")
  MenuList.Add("Orange")
  MenuList.Add("Grapes")
  MenuList.Add("Pineapple") 
  MenuList.Add("Mango")

  'Call the Sub
  ShowSingleChoiceMenu
End Sub

Sub ShowSingleChoiceMenu
  sd1.Initialize("sd1")
'The following will display the menu with the default selection pointing to the index value of nUserChoice
  sd1.Show("List of Fruits",MenuList,nUserChoice,"OK","Cancel") 
End Sub

Sub sd1_SingleChoice(Index As Int,Text As String)
  nUserChoice = Index

  Select Index
    Case 0
     
    Case 1
     
    Case 2
     
    Case 3
     
    Case 4
     
  End Select
 
End Sub

Regards
Anser
 

Anser

Well-Known Member
Licensed User
Longtime User
I tried the following code to achieve what I have specified in my previous post. Unfortunatley, it is not working as expected. I am sure that I have not understood how to use this lib. I could not locate any samples too.

After selecting an item in the list, the event is not fired.

B4X:
Sub Globals
    Dim sd1 as MaterialDialog
End Sub

Sub Activity_Create(FirstTime As Boolean)'Default Selected nUserChoice = 2

   'Call the Sub ShowSingleChoiceMenu
   ShowSingleChoiceMenu
End Sub

Sub ShowSingleChoiceMenu
    sdi.Initialize("sd1")
    sd1.items(Array As String("Apple", "Orange", "Grapes","Pineapple","Mango" ))
    sd1.title("List of Fruits")
    sd1.positiveText("OK")
    sd1.negativeText("Cancel")
    'sd1.autoDismiss(False)
    sd1.itemsCallbackSingleChoice(0) 'Default Selected Item
    sd1.show

End Sub

'The following event is not fired
Sub sd1_onSingleChoiceSelect (v As View, index As Int, text As String)
    Msgbox(text &CRLF& index,"" )
End Sub

Edit:- Can anybody tell me what is this itemsCallbackSingleChoice (selectedIndex As Int)

As per the instructions there is only one parameter to this call ie selectedIndex, but reading the instruction I understand that it is expecting one more parameter callback ie
callback: The callback that will be called when the presses the positive button.
  • itemsCallbackSingleChoice (selectedIndex As Int) As MaterialDialogBuilder
    Pass anything below 0 (such as -1) for the selected index to leave all options unselected initially.
    Otherwise pass the index of an item that will be selected initially.
    selectedIndex: The checkbox index that will be selected initially.
    callback: The callback that will be called when the presses the positive button.
    Return type: @return:The Builder instance so you can chain calls to it.
 
Last edited:

Anser

Well-Known Member
Licensed User
Longtime User
I have also noticed another issue.

If ypu call sd1.show more than once, it will not work properly. If you call sd1.show second time, the dialog will be displayed, but you will not be able to pick/choose an item from the list.

For eg.
As per my above given example if you put the call to the Sub ShowSingleChoiceMenu in some button_click, you can reproduce the issue.

Regards
Anser
 

asales

Expert
Licensed User
Longtime User
I tried to made this example:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
   
    #AdditionalJar: android-support-v4   
    #AdditionalRes: $AndroidSDK$\extras\android\support\v7\appcompat\res, android.support.v7.appcompat   
    #AdditionalRes: $AdditionalLibs$\b4a_appcompat, de.amberhome.objects.appcompat

#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
  Dim dialog As MaterialDialog
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    dialog.Initialize("Dialog")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    Log("Button_Click")
    dialog.positiveText("Cool!").negativeText("Oh nooo").neutralText("I dont care").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("DonManfred presents").content("afollestad´s MaterialDialogs").iconRes("donmanfred").dividerColor(Colors.Cyan).autoDismiss(False).buttonRippleColor(Colors.Gray).show   
End Sub

but I get this error:
B4X:
** Activity (main) Resume **
Button_Click
main_button1_click (java line: 354)
android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1136)
    at android.content.res.Resources.getDrawable(Resources.java:711)
    at android.support.v4.content.res.ResourcesCompat.getDrawable(ResourcesCompat.java:53)
    at com.afollestad.materialdialogs.MaterialDialog$Builder.iconRes(MaterialDialog.java:669)
    at de.donmanfred.MaterialDialogBuilder.iconRes(MaterialDialogBuilder.java:358)
    at b4a.example.materialdialog.main._button1_click(main.java:354)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:4584)
    at android.view.View$PerformClick.run(View.java:18568)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5214)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:814)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:630)
    at dalvik.system.NativeStart.main(Native Method)

Where I am wrong?
 

MTV

Member
Licensed User
Hello
How to set item's gravity ?
 

chefe82

Member
Licensed User
Longtime User
If I have done with the types shown below in the selection dialog a selection I always get an error message with the crash App.
What 's wrong?

B4X:
Dim DL As MaterialDialog ' in Globals

Sub lboeffnen_Click
    If manager.GetBoolean("vibrate") = True Then
        mv.vibrateOnce(40)
    End If
  
    DL.Initialize("dl1")
    DL.items(Array As String("1", "2", "3", "4"))
    DL.title("Bitte auswählen!!")
    DL.positiveText("OK")
    DL.negativeText("Schliessen")
    DL.itemsCallbackSingleChoice(0)
    DL.show
 
End Sub

Sub dl1_onSingleChoiceSelect(v As View, index As Int, text As String)
    lboeffnenText = text
End Sub

Error from the Log

LogCat connected to: HT3AATP00659
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (frmstartseite) Pause, UserClosed = false **
** Activity (frmauswahl) Create, isFirst = true **
** Activity (frmauswahl) Resume **
lib: NOTFOUND 'dl1_onshow
lib: NOTFOUND 'dl1_onpositive
lib:Raising.. dl1_onsinglechoiceselect()
lib: NOTFOUND 'dl1_onany
java.lang.Exception: Sub dl1_onsinglechoiceselect signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:171)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
 
Top