Bug? SeekBar ignoring values assigned in code

ipower

New Member
Licensed User
Longtime User
Hi,

I have an app with a SeekBar called SB. When I load activity I read SB initial value from a file and apply the value to the bar (SB.Value = s). But when I compile app shows a Java error: SB needs to be Initialized. So I wrote this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Config")
    [...]
    If SB.IsInitialized Then
        SB.Value = s
    Else
        SB.Initialize("SeekBar1")
        SB.Tag = s
        SB.Value = SB.Tag
    End If
[...]
When I'm typing SB.IsInitialized the IDE alerts me only to do that if SeekBar is not in designer. It is. But my phone alerts me that is not initialized, so I added the If ... Else anyway.

But when compiling code SeekBar never changes their value to match the s parameter, but no errors this time.
 

stevel05

Expert
Licensed User
Longtime User
Can you zip and post your code or a small project that shows the problem. There must be a problem in the designer set-up or elsewhere in your code.

If it's setup correctly in the designer, you have loaded the correct layout file and you have the correct variable name Dimmed, you wouldn't see that problem.
 

ipower

New Member
Licensed User
Longtime User
Your code is wrong. You shouldn't initialize views added with the designer. Can you post the complete Activity_Create code?
I know I shouldn't, but If I don't the phone show me that error "is not initialized"
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Config")
'    lav.Text=GetPackageName
    If File.Exists(File.DirInternal, "trans.txt") = True Then
            s = File.ReadString(File.DirInternal, "trans.txt")
            muestra.Bitmap = LoadBitmap(File.DirAssets, "panel" & s & ".png")
            lt.Text = s
            If SB.IsInitialized Then
                SB.Value = s
            Else
                SB.Initialize("SeekBar1")
                SB.Tag = s
                SB.Value = SB.Tag
            End If
    End If             
    imgf.Width = Activity.Width
    imgf.Height = Activity.Height
    'lav.Text = GetPackageName
End Sub
 

ipower

New Member
Licensed User
Longtime User
Here is my project. I saved it in the new B4A 3.2 version
 

Attachments

  • widget.zip
    261.3 KB · Views: 212
Top