B4A Library Dialogs library

Status
Not open for further replies.

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

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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…