B4A Library Dialogs library

Status
Not open for further replies.
This library contains several modal, that is blocking, dialogs by which the user can enter data. Presently they are an InputDialog for numbers and text, a TimeDialog for times and and a DateDialog for dates.

Note that modal dialogs can close unexpectedly and not return to your code if the Activity needs to close, most likely because the user rotated the device. There is a brief discussion of this in the overall library help in the xml. This can also occur with the Basic4android modal dialogs InputList, InputMultiList, Msgbox and Msgbox2 whose modal mechanism is used by the dialogs in this library.

Edit : - Version 1.1 posted with minor bug fix. See post #6 for details.

Edit : - Version 1.2 posted with Color dialogs. See post #16 for details.

Edit : - Version 1.3 posted with bug fix. See post #19 for details.

Edit : - Version 1.4 posted with a Number dialog. See post #20 for details.

Edit : - Version 1.5 posted with some enhancements. See post #28 for details.

Edit : - Version 1.6 posted with a File Dialog. See post #30 for details.

Edit : - Version 1.7 posted with a minor UI change. See post #33 for details.

Edit : - Version 1.8 posted with a Custom dialog. See post #37 for details.

Edit : - Version 1.9 posted with a bug fix. See post #42 for details.

Edit : - Version 2.0 posted with a bug fix. See post #48 for details.

Edit : - Version 2.1 posted with a second Custom dialog. See post #68 for details.

Edit : - Version 2.2 posted. See post #75 for details.

Edit : - Version 2.3 posted. See post #90 for details.

Edit : - Version 2.4 posted. See post #135 for details.

Edit : - Version 2.5 posted. See post #148 for details.

Edit : - Version 2.6 posted. See post #155 for details.

Edit : - Version 2.7 posted. See post #168 for details.

Edit : - Version 2.8 posted. See post #206 for details.

Edit :- Version 2.91 posted by Mildev. See post #317 for details. His version 2.91 is based on my unpublished v2.9 which set the text box in FileDialog to SingleLine mode.

Edit : - Version 2.92 posted. See post #341 for details.

Edit (Erel): Version 3.00 posted. Developers using B4A v6.80+ should use this version.

V4.01 is released with several improvements: https://www.b4x.com/android/forum/t...-dialogs-and-async-methods.80204/#post-507930

B4A version | Dialogs library version
------------------------------------
7.0+ 4+
6.8 3.00
<6.8 2.92
 

Attachments

  • Dialogs2.92.zip
    59.4 KB · Views: 12,994
  • Dialogs3.00.zip
    48.9 KB · Views: 2,947
  • Dialogs4.01.zip
    72.2 KB · Views: 9,560
Last edited by a moderator:

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I am using the following code and when I enter text into my Dialog and press Yes the keypad says open and doesn't close.

Is there a way to close the keypad when you click the button?

B4X:
Dim Id As InputDialog
   Dim ret As String 
   Bmp.Initialize(File.DirAssets, "icon.png")
   Id.InputType = Id.INPUT_TYPE_TEXT
   Id.Input = ""
   Id.Hint = "This is my hint"
   Id.HintColor = Colors.DarkGray 
   
   ret =  Id.Show("Please enter something", "This is my title", "Yes", "Cancel", "",Bmp)
   Msgbox(ret,"Selection")

I haved tried using IME.HideKeyboard but it didn't close.

Any other ways to close it?
 

Penko

Active Member
Licensed User
Longtime User
Why would you need to close it in a dialog? I asked about the opposite(how to show the keyboard when I show the dialog) but someone said that is pretty hard. If there id no obvious method to hide it, probably it is hard too. However, why do you need it as the user inputs something' they press the button and the dialog is being hidden?

Sent from my Next7P12 using Tapatalk 2
 

aaronk

Well-Known Member
Licensed User
Longtime User
what is happening is this..

- Dialog opens
- tap on the textbox and keypad displays
- enter your data into the dialog
- press the 'yes' button in the dialog and dialog goes away
- keypad still displays and won't go away.

Everything seems to work but the keypad won't go when the dialog is not shown.
 
Last edited:

Penko

Active Member
Licensed User
Longtime User
That's pretty strange. My keyboard hides perfectly after I click any of the buttons. It is the way dialogs work. What InputType do you use? Also, it may be a problem on your specific device. Is this yournfull code?

P.s I can't test now but it seems you have some errors. Check, but I think you have to check .Input after .Show() in order to understand what has the user typed. Also, it is good to know what button has been clicked. Test against the enum values in DialogResponse.Type.

The clicked button should be in .Response after .Show

Sent from my Next7P12 using Tapatalk 2
 
Last edited:

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

got it to work.

Just need to replace my messagebox with:

B4X:
Msgbox(Id.Input  ,"Selection")

and now the keypad goes away after they press the button.
 

Ennesima77

Member
Licensed User
Longtime User
Hi Everybody,
i'm just a beginner and sorry for my english.
There's the possibility to use TimerDialog to set Hour Minutes and Second?
I need it for a Count Down timer ad sometime it's possibile that the user need to set also second.

Thansk a lot for your kindly response.
 

Ennesima77

Member
Licensed User
Longtime User
You can easily write a class to expand with this functionality. All you need to do is define a CustomDialog inside and add the views for hours and seconds.


Sent from my Next7P12 using Tapatalk 2
There's some example or documentation about that?
I'm just a beginner and I haven't any idea to perform that.

Thanks a lot for your patience.
 

Penko

Active Member
Licensed User
Longtime User
I wrote something which is not complete. I called it DurationDialog. I will provide the code but you have to finish it yourself. That will happen a little bit later when I get back on my PC. I will edit this post with the code.

Sent from my HTC Desire using Tapatalk

Edit: Here you have the code.

Please note the following:
1) the code is not finished
2) not optimized
3) there is no "seconds" capability. You have to implement it yourself. It's not too hard.
4) there are some bugs if the user presses a button other than the Positive one.
5) setDuration doesn't set the duration at all. The fields do not take the appropriate value.
6) I am giving this code out as a hint and guide on what you have to do. There might be a better solution :).
7) the fields aren't arranged for production but for testing only. You have to fine tune the positions of both the Labels, and the EditTexts.

B4X:
' add this to a new class module. I've used cDurationDialog
'Class module
Sub Class_Globals

   Private theDialog As CustomDialog

   Private p_hours As Int
   Private p_minutes As Int
   
   Private pnlContainer As Panel
   
   Private lbHours As Label
   Private lbMinutes As Label
   
   Private txtHours As EditText
   Private txtMinutes As EditText
   
   Dim lbRealPreparationInterval As Label
   Dim lbRealPreparationIntervalValue As Label
End Sub


'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
   DrawPanel
End Sub

' Does all the internal job to visualize the dialog
Private Sub DrawPanel()

   ' initialize the labels
   lbHours.Initialize("")
   lbHours.Text = "Hours: "
   
   lbMinutes.Initialize("")
   lbMinutes.Text = "Minutes: "

   ' initialize the edittexts
   txtHours.Initialize("")
   txtHours.InputType = txtHours.INPUT_TYPE_PHONE
   txtMinutes.Initialize("")
   txtMinutes.InputType = txtMinutes.INPUT_TYPE_PHONE
   
   ' initialize the container
   pnlContainer.Initialize("")
   
   ' add the labels to the container
   pnlContainer.AddView(lbHours, 5dip, 0, 70dip, 50dip)
   pnlContainer.AddView(lbMinutes, 5dip, lbHours.Top + lbHours.Height + 5dip, 70dip, 50dip)
   
   pnlContainer.AddView(txtHours, lbHours.Left + lbHours.Width + 5dip, lbHours.Top, 50dip, 50dip)
   pnlContainer.AddView(txtMinutes, lbMinutes.Left + lbMinutes.Width + 5dip, lbMinutes.Top, 50dip, 50dip)

   ' add the container to the dialog
   theDialog.AddView(pnlContainer, 0, 0, 30%x, 30%y)

End Sub

' sets the duration as hours, minutes
Public Sub SetDuration(hours As Int, minutes As Int)
   
   Try
      p_hours = hours
   Catch
      p_hours = 0
   End Try
   
   Try
      p_minutes = minutes
   Catch
      p_minutes = 0
   End Try
   
   txtHours.Text = p_hours
   txtMinutes.Text = p_minutes
   
   
End Sub

' shows the dialog
Public Sub Show(Title As String, Positive As String, Cancel As String, Negative As String, icon As Bitmap)
   
   DrawPanel

   theDialog.Show(Title, Positive, Cancel, Negative, Null)

   p_hours = txtHours.Text
   p_minutes = txtMinutes.text
   
End Sub

' returns the hours value
Public Sub GetHours() As Int
   Return p_hours
End Sub

' returns the minutes value
Public Sub GetMinutes() As Int
   Return p_minutes
End Sub

' returns everything as minutes. Suitable for storing in DB, etc...
Public Sub GetAllAsMinutes()
   Return GetHours * 60 + GetMinutes
End Sub

' returns the stringified representation of the duration
Public Sub GetFullString()
   Return GetHours & "hours, " & GetMinutes & " minutes"
End Sub

' sets the hours of the dialog
Public Sub SetHours(hours As Int)
   p_hours = hours
End Sub

' sets the minutes of the dialog
Public Sub SetMinutes(minutes As Int)
   p_minutes = minutes
End Sub

' sets everything as minutes. Suitable when loading from DB. The dialog correctly calculates the hours and the remaining
' is shown as minutes.
Public Sub SetAllAsMinutes(minutes As Int)
   
   p_hours = minutes / 60
   p_minutes = minutes Mod 60
   
End Sub

' Wraps Andrew's Dialogs library .Response Property
Public Sub Response()
   Return theDialog.Response
End Sub

' Wraps Andrew's Dialogs library .Version Property
Public Sub Version()
   Return theDialog.Version
End Sub

The use:
B4X:
Sub Button3_Click

   Dim durationDialog As cDurationDialog
   durationDialog.Initialize
   durationDialog.SetDuration(0, 15)
   durationDialog.Show("Please set duration", "OK", "Cancel", "", Null)
   
   Msgbox(durationDialog.GetHours, "")
   
End Sub

Se hai problemi, scrivi :)
 
Last edited:

Ennesima77

Member
Licensed User
Longtime User
Thanks for you kindly reply:
I perform some goodnes:

B4X:
' add this to a new class module. I've used cDurationDialog
'Class module
Sub Class_Globals

    Private theDialog As CustomDialog

    Private p_hours As Int
    Private p_minutes As Int
    Private p_seconds As Int
   
    Private pnlContainer As Panel
    
    'Private lbHours As Label
    'Private lbMinutes As Label
    'Private lbSeconds As Label
   
    Private txtHours As EditText
    Private txtMinutes As EditText
    Private txtSeconds As EditText
   
   Private bttHoursP As Button
   Private bttHoursM As Button
   Private bttMinutesP As Button
   Private bttMinutesM As Button
   Private bttSecondsP As Button
   Private bttSecondsM As Button
   
    Dim lbRealPreparationInterval As Label
    Dim lbRealPreparationIntervalValue As Label
       
End Sub


'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    DrawPanel
End Sub

' Does all the internal job to visualize the dialog
Private Sub DrawPanel()

    ' initialize the labels
    'lbHours.Initialize("")
    'lbHours.Text = "Ore: "  
    'lbMinutes.Initialize("")
    'lbMinutes.Text = "Minuti: "
    'lbSeconds.Initialize("")
    'lbSeconds.Text = "Secondi: "

    ' initialize the edittexts
    txtHours.Initialize("")
   txtHours.TextSize=35
   txtHours.Gravity=1
    txtHours.InputType = txtHours.INPUT_TYPE_PHONE
   
    txtMinutes.Initialize("")
   txtMinutes.TextSize=txtHours.TextSize
   txtMinutes.Gravity=1
    txtMinutes.InputType = txtMinutes.INPUT_TYPE_PHONE
   
    txtSeconds.Initialize("")
   txtSeconds.TextSize=txtHours.TextSize 
   txtSeconds.Gravity=1
    txtSeconds.InputType = txtMinutes.INPUT_TYPE_PHONE
   
   'initialize the buttin
   bttHoursP.Initialize("bttHoursP")
   bttHoursP.Text = "+"
   bttHoursP.TextSize = 20
   bttHoursP.Typeface = Typeface.DEFAULT_BOLD 
   
   bttHoursM.Initialize("bttHoursM")
   bttHoursM.Text = "-"
   bttHoursM.TextSize = bttHoursP.TextSize 
   bttHoursM.Typeface = bttHoursP.Typeface  
   
   
   bttMinutesP.Initialize("bttMinutesP")
   bttMinutesP.Text = "+"
   bttMinutesP.TextSize = bttHoursP.TextSize 
   bttMinutesP.Typeface = bttHoursP.Typeface  
   
   bttMinutesM.Initialize("bttMinutesM")
   bttMinutesM.Text = "-"
   bttMinutesM.TextSize = bttHoursP.TextSize 
   bttMinutesM.Typeface = bttHoursP.Typeface 
   
   
   bttSecondsP.Initialize("bttSecondsP")
   bttSecondsP.Text = "+"
   bttSecondsP.TextSize = bttHoursP.TextSize 
   bttSecondsP.Typeface = bttHoursP.Typeface 
   
   bttSecondsM.Initialize("bttSecondsM")
   bttSecondsM.Text = "-"
   bttSecondsM.TextSize = bttHoursP.TextSize 
   bttSecondsM.Typeface = bttHoursP.Typeface 
   
    ' initialize the container
    pnlContainer.Initialize("")
    
    ' add the labels to the container
    'pnlContainer.AddView(lbHours, 5dip, 0, 70dip, 50dip)
    'pnlContainer.AddView(lbMinutes, 5dip, lbHours.Top + lbHours.Height + 5dip, 70dip, 50dip)
    'pnlContainer.AddView(lbSeconds, 5dip, lbMinutes.Top + lbHours.Height + 5dip, 70dip, 50dip)
   
    pnlContainer.AddView(txtHours, 30dip, 70dip, 80dip, 70dip)
    pnlContainer.AddView(txtMinutes, txtHours.Left + txtHours.Width + 10dip , txtHours.Top, txtHours.Width, txtHours.Height)
   pnlContainer.AddView(txtSeconds, txtMinutes.Left + txtMinutes.Width + 10dip, txtHours.Top, txtHours.Width, txtHours.Height)
   
   pnlContainer.AddView(bttHoursP, txtHours.Left + 10dip, txtHours.Top - 50dip, 60dip,  40dip)
   pnlContainer.AddView(bttHoursM, txtHours.Left + 10dip, txtHours.Top + txtHours.Height + 10dip, bttHoursP.Width, bttHoursP.Height)
   pnlContainer.AddView(bttMinutesP, txtMinutes.Left + 10dip, txtHours.Top - 50dip, 60dip,  40dip)
   pnlContainer.AddView(bttMinutesM, txtMinutes.Left + 10dip, txtHours.Top + txtHours.Height + 10dip, bttHoursP.Width, bttHoursP.Height)
   pnlContainer.AddView(bttSecondsP, txtSeconds.Left + 10dip, txtHours.Top - 50dip, 60dip,  40dip)
   pnlContainer.AddView(bttSecondsM, txtSeconds.Left + 10dip, txtHours.Top + txtHours.Height + 10dip, bttHoursP.Width, bttHoursP.Height)
   
    ' add the container to the dialog
    theDialog.AddView(pnlContainer, 0, 0,  300dip, 200dip)

End Sub


' shows the dialog

#Region "Show Method"

Public Sub Show(Title As String, Positive As String, Cancel As String, Negative As String, icon As Bitmap)
    
    DrawPanel
   
    txtHours.Text = p_hours
    txtMinutes.Text = p_minutes
    txtSeconds.Text = p_seconds
   
    theDialog.Show(Title, Positive, Cancel, Negative, Null)

    p_hours = txtHours.Text
    p_minutes = txtMinutes.text
    
End Sub
Public Sub ShowSet(Title As String, Positive As String, Cancel As String, Negative As String, icon As Bitmap, Hours As Int, _
               Minutes As Int, Seconds As Int)
    
    DrawPanel
   
    SetDuration(Hours, Minutes,Seconds)
   
    theDialog.Show(Title, Positive, Cancel, Negative, Null)

    p_hours = txtHours.Text
    p_minutes = txtMinutes.text
    p_seconds = txtSeconds.Text 
   
End Sub
Public Sub ShowSetSec(Title As String, Positive As String, Cancel As String, Negative As String, icon As Bitmap, Seconds As Int)
    
    DrawPanel
   
    SetSeconds(Seconds)
   
    theDialog.Show(Title, Positive, Cancel, Negative, Null)

    p_hours = txtHours.Text
    p_minutes = txtMinutes.text
    p_seconds = txtSeconds.Text 
   
End Sub

#End Region
#Region "Button Event"
Sub bttHoursM_Click
   If p_hours>0 Then
      p_hours = p_hours - 1
      txtHours.Text = p_hours   
   End If
End Sub
Sub bttHoursP_Click
   p_hours = p_hours + 1
   txtHours.Text = p_hours
End Sub

Sub bttMinutesM_Click
   If p_minutes>0 Then
      p_minutes = p_minutes - 1
      txtMinutes.Text = p_minutes
   End If
End Sub
Sub bttMinutesP_Click
   p_minutes = p_minutes + 1
   txtMinutes.Text = p_minutes
End Sub

Sub bttSecondsM_Click
   If p_seconds>0 Then
      p_seconds = p_seconds - 1
      txtSeconds.Text = p_seconds   
   End If
End Sub
Sub bttSecondsP_Click
   p_seconds = p_seconds + 1
   txtSeconds.Text = p_seconds
End Sub

#End Region

#Region "Get Method"

' returns the hours value
Public Sub GetHours() As Int
    Return p_hours
End Sub
' returns the minutes value
Public Sub GetMinutes() As Int
    Return p_minutes
End Sub
' returns the minutes value
Public Sub GetSeconds() As Int
    Return p_seconds
End Sub

' returns everything as minutes. Suitable for storing in DB, etc...
Public Sub GetAllAsSeconds()
    Return GetHours * 3600 + GetMinutes * 60 + GetSeconds
End Sub

' returns the stringified representation of the duration
Public Sub GetFullString()
    Return NumberFormat(GetHours,2,0) & ":" & NumberFormat(GetMinutes,2,0) & ":" & NumberFormat(GetSeconds,2,0)
End Sub


#End Region

#Region "Set Method"

' sets the duration as hours, minutes
Public Sub SetDuration(hours As Int, minutes As Int, seconds As Int)
    
    Try
        p_hours = hours
    Catch
        p_hours = 0
    End Try
    
    Try
        p_minutes = minutes
    Catch
        p_minutes = 0
    End Try
    
   Try
        p_seconds = seconds
    Catch
        p_seconds = 0
    End Try
   
    txtHours.Text = p_hours
    txtMinutes.Text = p_minutes
    txtSeconds.Text = p_seconds
    
End Sub

' sets the hours of the dialog
Public Sub SetHours(hours As Int)
    p_hours = hours
End Sub
' sets the minutes of the dialog
Public Sub SetMinutes(minutes As Int)
    p_minutes = minutes
End Sub
' sets the seconds of the dialog
Public Sub SetSeconds(seconds As Int)
    p_minutes = seconds
End Sub
' sets everything as minutes. Suitable when loading from DB. The dialog correctly calculates the hours and the remaining
' is shown as minutes.
Public Sub SetAllAsSeconds(Seconds As Int)
    
    p_hours = Seconds / 3600
    p_minutes = (Seconds/60 - p_hours*60) '(Seconds - p_hours*3600) / 60
    p_seconds = Seconds Mod 60
   
End Sub

#End Region

' Wraps Andrew's Dialogs library .Response Property
Public Sub Response()
    Return theDialog.Response
End Sub

' Wraps Andrew's Dialogs library .Version Property
Public Sub Version()
    Return theDialog.Version
End Sub

it can be show with 3 different method
Show it's equal of original one
ShowSet: it's possible view the DialogBox and send Hours, Minute and Second at the same
ShowSetSec: it's possible view the DialogBox and send the total second.

It's possible to Set and Get all in Seconds or Fulltime in HH:mm:ss format.

I Have had + and - button for Hours, Minutes and Second.

For a better order I used Region.

Grazie mille ancora.
 

Ennesima77

Member
Licensed User
Longtime User
It's also possible more than one inside a region
#region "Primary"
#Region "Secondary"

#End Region

#Region "Secondary"

#End Region

#end region

it's soo useful with a very long code, I'm onest I try it in Visual Basic style without read nothing about that in the manual and it works.
(Sa' mai che ho detto ua cacchiata ti traduco quello che volevo dire:
E' davvero comodo con codici lunghi, ho provato a scrivere #Region come facevo in visual basic .net e ho visto che funziona bene allora per abitudine continua ad usarlo :))
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
How likely would it be to get the Time Dialog to use the Date portion of the Ticks passed to it and return that with the time set instead of the weird Dec 31st 0002 date? I had a weird issue in a Bug thread Erel may have mentioned to you earlier too where apparently there is some sort of disconnect between Get and Set ticks where one uses the default DateTime object and the other uses their own. Having it use the whole ticks passed and just modify the date would fix both issues I think and make it more functional in handling tick values to be used elsewhere without the DateTime object shifting the ticks from it wrong.
 

nemethv

Member
Licensed User
Longtime User
Anyone had success in adding a ScrollView to a CustomDialog2?

I wanted to create a dialog with scrollable contents and this doesn't seem to be possible. If it is possible and I can't figure out how to do it a simple example would be great.

If it is not possible I think I will have to use a seperate activity instead of the dialog.

Thanks,
Markus

I'd love to know that too...
 

nemethv

Member
Licensed User
Longtime User
I think this has been asked but not answered.
(How) is it possible to close/hide a listview when the user clicks on an item. There's nothing like cd.hide or lv.hide or anything similar.
I'm trying to offer a selection from a list but want to avoid buttons.
 

mhdi

Member
Licensed User
Longtime User
B4X:
cd.Show("", "OK", "CANCEL", "",Null)

How do I do something once the user presses OK or CANCEL on a CustomDialog

I know this is simple, sorry.
 
Status
Not open for further replies.
Top