Custom Dialog with Seekbar Problem

Flosch

Member
Licensed User
Longtime User
Hi, I want to create a custom dialog with a seekbar.

If you move the seekbar i want to show the actual value on a label.
I tried it with a ValueChanged sub but this sub is only called if I close the dialog not when the dialog is shown. What's wrong?

Here is the code:
B4X:
'Activity module
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 btnCustom As Button
   Dim lbl1, lbl_Test As Label
   Dim SeekBar1 As SeekBar
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Layout")
   lbl_Test.Text = ""
   SeekBar1.Initialize("SeekBar1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnCustom_Click
      Dim cd As CustomDialog2
      Dim cd_pnl As Panel 
      cd_pnl.Initialize("cd_pnl")
      'Seekbar
      Dim seek As SeekBar
      seek.Initialize("seek")
      lbl1.Initialize("")
      seek.Max = 100
      seek.Value = 50
      cd_pnl.AddView(seek, 10dip, 45dip, 77%x-20dip, 30dip )
      'Label
      lbl1.Initialize("")
      lbl1.Gravity = Gravity.CENTER 
      lbl1.Text = seek.Value & "%"
      lbl1.TextColor = Colors.LightGray
      lbl1.TextSize = 18
      lbl1.Typeface = Typeface.DEFAULT
      cd_pnl.AddView(lbl1, 10dip,  10dip, 77%x-20dip, 25dip)

      cd.AddView(cd_pnl, 77%x, 90dip)
      ret = cd.Show("Test", "Yes", "No", "Maybe", Null)
End Sub

'Seekbaar Value Changed in Dialog
Sub seek_ValueChanged (Value As Int, UserChanged As Boolean)
      lbl1.Text = Value & "%"
End Sub

'To test it in "normal" view
Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
   lbl_Test.Text = Value & "%"
End Sub

Thanks for your help.
 

Attachments

  • Dialog-Test.zip
    2.2 KB · Views: 291

mc73

Well-Known Member
Licensed User
Longtime User
I've tested your app, and the label of the dialogBox is being changed when you use the seekbar. Perhaps you mean something else?
 
Upvote 0

Flosch

Member
Licensed User
Longtime User
Ok that is strange.

At my phone the label in the Dialog doesn't change. It will work well in the normal screen. But if the dialog is in front, the label in the dialog (lbl1) dosen't change if you move the seekbar.
While the dialog is shown the (Sub seek_ValueChanged (Value As Int, UserChanged As Boolean)) is not called at all. As soon as the diolog is closed the sub is called multiple times.

For testing I use a Samsung Galaxy S1 (Android 2.3.3)

I dont't know what's wrong!
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
The problem is that the ValueChanged events will not be raised as long as the modal dialog is displayed. You will need to use a non-modal dialog instead.

But why is it working for me, then?
 
Upvote 0

Flosch

Member
Licensed User
Longtime User
I'm using 2.02

So I can't use the Dialog Lib?
Is there a lib or an example for non-modal dialogs?
That would help a lot.
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Erel, I use panels but find views underneath them receive the click. Is there a way to stop this?

Regards, Ricky
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Erel, I use panels but find views underneath them receive the click. Is there a way to stop this?

Regards, Ricky
one way to do this is to set a flag to true whenever you have this panel active. then you can check inside the events of these views for this flag and avoid their code execution.
if your panel overlays all these views, you can return 'true' from its touch event. this way you will consume clicks.
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Thanks I'll put that in place when I get home after work.

Regards, Ricky
 
Upvote 0

Flosch

Member
Licensed User
Longtime User
I'm a little bit confused and just want to get it right:

I can't use the Dialolg Lib in this particular case bacause it is a modual diaolg.

To get this function I have to write my own Non-Modual Dialog with a seekbar and the Ok / Cancel buttons.

Is that right or is there a way to use the Dialog Lib?
 
Upvote 0

RomansUP

Member
Licensed User
Longtime User
I have got the same problem with rising event of Seekbar changes but only after I have upgrade version of Basic4Androi from 1.70 to 2.50. Also after this upgrade there is a problem with rising events such as Button_down and Button_up if you use it in CustomDialog. Before in version 1.70 there are not these problems. So now I must change program code to fix these type of problem with such events. :BangHead:
 
Upvote 0
Top