Italian B4XDialog Autoresize

Xfood

Expert
Licensed User
ciao a tutti,
scusate per l'orario
sto utilizzando B4xdialog invece di Msgbox2Async,
lo trovo piu funzionale,
ma purtroppo se scrivo un messaggio lungo non si autoresiza,
qualcuno sa come fare in modo tale che se il messaggio e' un po piu lungo del normale si autoresiza?

il codice che uso e' questo

B4X:
Sub Globals
Private Dialog_Messaggio As B4XDialog
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dialog_Messaggio.Initialize(Activity)
Dialog_Messaggio.Title = "Test1"
Wait For (Dialog_Messaggio.Show("L'azzeramento dei movimenti non verrà effettuata perchè il trasferimento sul Server FTP non è andato a buon fine." & CRLF & "Si consiglia di risolvere il problema e riprovare, oppure effettuare l'esportazione in locale.","OK","","")) Complete (Result As Int)
End Sub
1665697465616.png


manca come si vede,[ effettuare l'operazione in locale.]

si puo gestire un sorta di autoresize del messaggio come faceva il vecchio Msgbox2Async

Grazie mille.
 

PaulMeuris

Well-Known Member
Licensed User
B4XDialog with resized panel:
Sub Globals
    Private strutils As StringUtils
    Private dialog As B4XDialog
    Private lblprompt As Label
    Private lbltitle As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
    dialog.Initialize(Activity)
    dialog.PutAtTop = True
    dialog.BackgroundColor = Colors.White
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0dip, 0dip, 0dip, 340dip, 100dip)
    pnl.LoadLayout("layout")
    lbltitle.Text = "Test1"
    lblprompt.Text = "L'azzeramento dei movimenti non verrà effettuata perchè il trasferimento sul Server FTP non è andato a buon fine." & CRLF & "Si consiglia di risolvere il problema e riprovare, oppure effettuare l'esportazione in locale."
    ' 3 times the original height
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    pnl.RemoveAllViews
    pnl.AddView(lblprompt,0dip,0dip,340dip,lblprompt.Height+50dip)
    ' resize the label
    lblprompt.Height = strutils.MeasureMultilineTextHeight(lblprompt,lblprompt.Text)
    ' resize the panel to fit the lblprompt
    pnl.SetLayoutAnimated(0,0dip,0dip,340dip,lblprompt.Height)
    Dim rsub1 As ResumableSub =  dialog.ShowCustom(pnl, "OK", "", "CANCEL")
    Wait For (rsub1) Complete (Result As Int)
    If Result = xui.dialogResponse_Positive Then
        '
    End If   
End Sub
I have found this code in my B4XDialog examples (inputdialog with resized prompt).
Happy coding!
 

Xfood

Expert
Licensed User
B4XDialog with resized panel:
Sub Globals
    Private strutils As StringUtils
    Private dialog As B4XDialog
    Private lblprompt As Label
    Private lbltitle As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
    dialog.Initialize(Activity)
    dialog.PutAtTop = True
    dialog.BackgroundColor = Colors.White
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0dip, 0dip, 0dip, 340dip, 100dip)
    pnl.LoadLayout("layout")
    lbltitle.Text = "Test1"
    lblprompt.Text = "L'azzeramento dei movimenti non verrà effettuata perchè il trasferimento sul Server FTP non è andato a buon fine." & CRLF & "Si consiglia di risolvere il problema e riprovare, oppure effettuare l'esportazione in locale."
    ' 3 times the original height
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    pnl.RemoveAllViews
    pnl.AddView(lblprompt,0dip,0dip,340dip,lblprompt.Height+50dip)
    ' resize the label
    lblprompt.Height = strutils.MeasureMultilineTextHeight(lblprompt,lblprompt.Text)
    ' resize the panel to fit the lblprompt
    pnl.SetLayoutAnimated(0,0dip,0dip,340dip,lblprompt.Height)
    Dim rsub1 As ResumableSub =  dialog.ShowCustom(pnl, "OK", "", "CANCEL")
    Wait For (rsub1) Complete (Result As Int)
    If Result = xui.dialogResponse_Positive Then
        '
    End If  
End Sub
I have found this code in my B4XDialog examples (inputdialog with resized prompt).
Happy coding!
Sarebbe bello creare una classe su questa base MsgboxDialog,
cosi da richiamarla direttamente

It would be nice to create a class on this basis MsgboxDialog,
so as to recall it directly
B4X:
Wait For (MsgboxDialog.Show("L'azzeramento dei movimenti non verrà effettuata perchè il trasferimento sul Server FTP non è andato a buon fine." & CRLF & "Si consiglia di risolvere il problema e riprovare, oppure effettuare l'esportazione in locale.","OK","","")) Complete (Result As Int)

qualcuno potrebbe creare una classe / lib su questa base? credo sarebbe utile a molti.

could someone create a / lib class on this basis? I think it would be useful to many.
 

PaulMeuris

Well-Known Member
Licensed User
And of course you need to add the lbltitle (after line 18) to the panel and shift the lblprompt down by setting the top at 50dip.
The panel height also increases with 50dip.
 
Last edited:

PaulMeuris

Well-Known Member
Licensed User
If the text is really long you can throw a scrollview in the mix like so:
scrolling message:
    dialog.Initialize(Activity)
    dialog.PutAtTop = True
    dialog.BackgroundColor = Colors.White
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0dip, 0dip, 0dip, 340dip, 100dip)
    pnl.LoadLayout("layout")
    lbltitle.Text = "Test1"
    lblprompt.Text = "L'azzeramento dei movimenti non verrà effettuata perchè il trasferimento sul Server FTP non è andato a buon fine." & CRLF & "Si consiglia di risolvere il problema e riprovare, oppure effettuare l'esportazione in locale."
    ' 3 times the original height
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    pnl.RemoveAllViews
    pnl.AddView(lblprompt,0dip,0dip,340dip,lblprompt.Height+50dip)
    ' resize the label
    lblprompt.Height = strutils.MeasureMultilineTextHeight(lblprompt,lblprompt.Text)
    ' resize the panel to fit the lblprompt
    pnl.SetLayoutAnimated(0,0dip,0dip,340dip,lblprompt.Height)
    Dim devheight As Int = GetDeviceLayoutValues.height - 40dip
    svdialog.Panel.AddView(pnl,0dip,0dip,340dip,pnl.Height)
    svdialog.Panel.Height = pnl.Height
    svdialog.Height = devheight-100dip
    Dim rsub1 As ResumableSub =  dialog.ShowCustom(svdialog, "OK", "", "CANCEL")
    Wait For (rsub1) Complete (Result As Int)
    If Result = xui.dialogResponse_Positive Then
        '
    End If
Make sure you add a scrollview to the layout.
This code works also in landscape when there is not much room to display a dialog!
Happy coding!
 

Xfood

Expert
Licensed User
If the text is really long you can throw a scrollview in the mix like so:
scrolling message:
    dialog.Initialize(Activity)
    dialog.PutAtTop = True
    dialog.BackgroundColor = Colors.White
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0dip, 0dip, 0dip, 340dip, 100dip)
    pnl.LoadLayout("layout")
    lbltitle.Text = "Test1"
    lblprompt.Text = "L'azzeramento dei movimenti non verrà effettuata perchè il trasferimento sul Server FTP non è andato a buon fine." & CRLF & "Si consiglia di risolvere il problema e riprovare, oppure effettuare l'esportazione in locale."
    ' 3 times the original height
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    lblprompt.Text = lblprompt.Text & CRLF & lblprompt.text & CRLF & lblprompt.text
    pnl.RemoveAllViews
    pnl.AddView(lblprompt,0dip,0dip,340dip,lblprompt.Height+50dip)
    ' resize the label
    lblprompt.Height = strutils.MeasureMultilineTextHeight(lblprompt,lblprompt.Text)
    ' resize the panel to fit the lblprompt
    pnl.SetLayoutAnimated(0,0dip,0dip,340dip,lblprompt.Height)
    Dim devheight As Int = GetDeviceLayoutValues.height - 40dip
    svdialog.Panel.AddView(pnl,0dip,0dip,340dip,pnl.Height)
    svdialog.Panel.Height = pnl.Height
    svdialog.Height = devheight-100dip
    Dim rsub1 As ResumableSub =  dialog.ShowCustom(svdialog, "OK", "", "CANCEL")
    Wait For (rsub1) Complete (Result As Int)
    If Result = xui.dialogResponse_Positive Then
        '
    End If
Make sure you add a scrollview to the layout.
This code works also in landscape when there is not much room to display a dialog!
Happy coding!
Thanks, the next step would be to create a b4xlib, to pass the parameters, Title, Color, Message, Buttons, and that would be really cool.

Too bad I'm still not very good at creating baxlib.

Grazie , il passo successivo sarebbe creare un b4xlib, a cui passare i parametri, Titolo,colore,Messaggio,Bottoni, e sarebbe veramente fantastico.

Peccato che ancora non sono molto bravo nella creazione delle baxlib.
 
Top