Android Question [SOLVED] Spinner is not disabled into a CustomDialog

antonomase

Active Member
Licensed User
Longtime User
Hi,

I want to use a spinner in a customDialog. It works fine except when I want to disable it. Setting enabled to false changes nothing.
On the other hand, setting visible to false makes the spinner invisible.
To check that the error wasn't in my code, I went back to the example [B4X] XUI Views - Cross platform views and dialogs

In the layout CustomDialog, I added a view SpinnerName.
In the code

B4X:
Sub Globals
    Private dialog As B4XDialog
    Private fieldFirstName As B4XFloatTextField
    Private fieldLastName As B4XFloatTextField
    Private SpinnerName As Spinner
End Sub
and
B4X:
Sub btnCustom_Click
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 300dip, 200dip)
    p.LoadLayout("CustomDialog")
    SpinnerName.Add("Value1")
    SpinnerName.Add("Value2")
    SpinnerName.Add("Value3")
    SpinnerName.Enabled = False
    ' SpinnerName.Visible = False   

    dialog.PutAtTop = True 'put the dialog at the top of the screen
    Wait For (dialog.ShowCustom(p, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        xui.MsgboxAsync(SpinnerName.SelectedItem & " " & fieldFirstName.Text & " " & fieldLastName.Text, "Result")
    End If
End Sub

The SpinnerName is displayed and stil active.

But if I remove the comment on the visibility line, SpinnerName is rendered invisible.

Why doesn't enabled/disabled work, whereas visible/invisible does?

Thanks for your answers
 

stevel05

Expert
Licensed User
Longtime User
I can't give you an explanation but It works if you code it like this:

B4X:
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 300dip, 200dip)
    p.LoadLayout("CustomDialog")
    SpinnerName.Add("Value1")
    SpinnerName.Add("Value2")
    SpinnerName.Add("Value3")
  

    Dialog.PutAtTop = True 'put the dialog at the top of the screen

    Dim RS As ResumableSub = Dialog.ShowCustom(p, "OK", "", "CANCEL")
  
    SpinnerName.Enabled = False
  
    Wait For (RS) Complete (Result As Int)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Thinking about it, it probably has to do with the fact that the panel (and therefore the spinner) is not added to the activity until the dialog is displayed. So when it's added, it probably takes the enabled value from the layout. You can change it after it's added using my code above.

I don't know why the Visible property behaves differently though.
 
Upvote 0

antonomase

Active Member
Licensed User
Longtime User
Thank you very much for this tip. I was in the process of setting up a transparent panel, whether to make it visible or not...

Indeed, why enabled and visible have different behaviors, those are the mysteries of computing! But in the meantime, it works.

Thanks again.
 
Upvote 0
Top