Android Question Spinner Visibility

iCAB

Well-Known Member
Licensed User
Longtime User
Hi All

I am facing an issue controlling the spinner visibility in code after changing the manifest file to include

B4X:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/>
instead of
B4X:
<uses-sdk android:minSdkVersion="8"/>

In particular, now, I have to set the spinner position and I must use Visible = true to show the spinner, which I didn't have to do previously. This code forced the spinner to get displayed regardless of Visible = true/false

B4X:
r.Target = spnNavSpinner
r.RunMethod("performClick")

In the original code, if the user clicked anywhere other than on the spinner, the spinner got dismissed and hidden. After the mods, the spinner gets dismissed but stays visible.

Is there a way to detect this event to hide the spinner?

Thanks in advance
 

JordiCP

Expert
Licensed User
Longtime User
I faced a similar problem, I needed to know when the spinner was dismissed to perform another action.
Based on a stackoverflow post (there were a lot regarding this issue, but only this one helped me, now I don't remember which), I did the following

Create a transparent ImageView with the same layout as the spinner and place it on its top
Declare a global var to track its state
The spinner will get open when you click on this IV --> so you can control the open event
Declare the Activity_FocusChanged event, which will raise each time there is a focus change
B4X:
Sub Globals
Dim spinnerState as int =0    ' 0=Closed, 1: open, 2=dismissed
Dim mySpinner as spinner
Dim IV as ImageView
End Sub

Sub Activity_Create(FirstTime as Boolean)
'....
' Let's suppose that at this point the spinner is already initted and added to the activity (change below lines accordingly if added to a Panel)
' Then we init the ImageView to capture the open event and place it over the spinner
IV.Initialize("IV")
IV.Color=Colors.Transparent
Activity.AddView(IV,mySpinner.left,mySpinner.Top,mySpinner.Width,mySpinner.height)
'....
End Sub

Sub IV_Click
  spinnerState=1
  Dim J As JavaObject = mySpinner
  J.RunMethod("performClick",Null)       'We open the spinner indirectly. If you open it by code, also set spinerState=1
End Sub

Sub  Activity_WindowFocusChanged (Focused As Boolean)
   'Log("Focus changed")
   If spinnerState=1 Then
     Log("spinner is OPEN")
     spinnerState=2
   Else if spinnerState>1 Then
     Log("spinner is CLOSED")
     spinnerState=0
   End If
End Sub

Based on the spinnerState value, you will be able to know when to perform the needed actions :)
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi JordiCP

Thanks for taking the time to reply. I will give it a try. But I was hoping that there is some sort of an event that gets raised when the spinner is dismissed.

Thanks again for your input, greatly appreciated
 
Upvote 0
Top