One item in spinner

johnaaronrose

Active Member
Licensed User
Longtime User
I have a spinner (named SpinnerCountry) populated by a column selected from a database table (using DBUtils.ExecuteSpinner). That works fine. Sometimes there is only one item. It seems to me rather pointless to make the user select that item. Is it allowed to call directly the item's click routine (i.e. SpinnerCountry_ItemClick)? If so, what would the parameters be (e.g. would Position be 0 and Value be SpinnerCountry.GetItem(0))?

PS Using DBUtils.ExecuteSpinner, it shows the first Country in the spinner's 'label' (on the screen at runtime). When I click the spinner box, it the comes up with a list headed by what I set Spinner.Prompt (i.e. "Please select Country"). It would be nice to see that value in the spinner box before I click on it. Any recommendations?
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I think I had a similar issue I reported in the Bug Wish Forum. My issue wasn't only with one item (although that would be high on the list), but that the spinner will show the item in the label like you said, but never fires the event saying it is the selected item. So, even though there is an item selected the user still has to click the spinner and select it again for the event to fire. I had already made the workaround Erel suggested in the thread about firing the event myself or in my case where I populated the spinner I do an [If spinner.SelectedIndex > -1 then] just after populating and just set my variable storing the selection. It isn't as modular or class friendly, but works until the event is fixed to fire...if ever.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Workaround in Thread

I think I had a similar issue I reported in the Bug Wish Forum. My issue wasn't only with one item (although that would be high on the list), but that the spinner will show the item in the label like you said, but never fires the event saying it is the selected item. So, even though there is an item selected the user still has to click the spinner and select it again for the event to fire. I had already made the workaround Erel suggested in the thread about firing the event myself or in my case where I populated the spinner I do an [If spinner.SelectedIndex > -1 then] just after populating and just set my variable storing the selection. It isn't as modular or class friendly, but works until the event is fixed to fire...if ever.

Roger,
Could you point me to the workaround?
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
The workaround was in the post text- You either call the even yourself providing it the needed values like you mentioned in your first post, or you test SelectedIndex of the spinner after adding items to it and if > -1 it means an item is selected, so you can store it in whatever manner that you do in the event to use later so they don't need to click it and select it when it already is.

You could also use a hybrid of the two and test if > -1 then call the event with the values needed. (Safer if it is possible that the spinner could have 0 values and you hardcode the GetItem(0) which would be out of bounds of the list)
 
Last edited:
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Spinner label after population of Spinner

The workaround was in the post text- You either call the even yourself providing it the needed values like you mentioned in your first post, or you test SelectedIndex of the spinner after adding items to it and if > -1 it means an item is selected, so you can store it in whatever manner that you do in the event to use later so they don't need to click it and select it when it already is.

You could also use a hybrid of the two and test if > -1 then call the event with the values needed. (Safer if it is possible that the spinner could have 0 values and you hardcode the GetItem(0) which would be out of bounds of the list)

Thanks Roger. I used .Size of the spinner to test if there are no items (so that I could inform the user etc) or 1 item (then calling Spinner_ ItemClick with Position 0f 0 & Value of GetItem(0, Spinner.GetItem(0)). Everything worked as expected.

Still one query as stated in PS of my message:
Using DBUtils.ExecuteSpinner, it shows the first item in the spinner's 'label' (on the screen at runtime). When I click the spinner box, it then comes up with a list headed by what I set Spinner.Prompt (i.e. "Please select Country"). It would be nice to see that value in the Spinner box before I click on it. Any recommendations?
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I have some code here in a View Manager class you may or may not have seen. I had lots of issues drawing spinners to begin with and along with this issue I have some code where I need the spinner to have a list sort of like a listview where it shows the user one thing and stores another value. I started changing the code to make a custom spinner using a label and a listview. I ran into issues drawing the listview since Activity isn't available in classes and then my wife had a baby. Haven't got to do much on it yet but plan to tweak it a little possibly this weekend. I'll update the code when finished.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
I have some code here in a View Manager class you may or may not have seen. I had lots of issues drawing spinners to begin with and along with this issue I have some code where I need the spinner to have a list sort of like a listview where it shows the user one thing and stores another value. I started changing the code to make a custom spinner using a label and a listview. I ran into issues drawing the listview since Activity isn't available in classes and then my wife had a baby. Haven't got to do much on it yet but plan to tweak it a little possibly this weekend. I'll update the code when finished.

Roger,
I haven't seen the View Manager class. If it's in Java, then I wouldn't understand it as I have zero knowledge of Java. I look forward to your 'publication'. I still haven't found a solution to the problem of setting a prompt without it being overwritten by DBUtils.ExecuteSpinner.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Question for Erel

Erel,

Using DBUtils.ExecuteSpinner, it shows the first item in the spinner's 'label' (on the screen at runtime before I click on it). When I click the spinner box, it then comes up with a list headed by what I set Spinner.Prompt to (e.g. "Please select Country"). It would be nice to see that value in the Spinner box before I click on it. Any ideas, apart from having it as a 'dummy' row in the database's table?
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Did you take a look at my View Manager Class above? It does this exact thing aside from tweaking the ExecuteSpinner method to work with it, and I just posted some example code yesterday showing the capabilities. The default behavior of the Spinner is to do what you describe and it has no text it can display other than what you provide, so a "Dummy" Record would be required to use it that way. You could tweak the ExecuteSpinner method to insert a prompt item in the spinner before the DB items to get a better effect too and don't have to put it in the DB if you wish to use the spinner.
 
Last edited:
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Did you take a look at my View Manager Class above? It does this exact thing aside from tweaking the ExecuteSpinner method to work with it, and I just posted some example code yesterday showing the capabilities. The default behavior of the Spinner is to do what you describe and it has no text it can display other than what you provide, so a "Dummy" Record would be required to use it that way. You could tweak the ExecuteSpinner method to insert a prompt item in the spinner before the DB items to get a better effect too and don't have to put it in the DB if you wish to use the spinner.

Roger,
I did take a look at it but I didn't understand how to use it let alone understanding the internals of it. Please remember that I'm not a professional programmer!
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Try modifying the ExecuteSpinner Sub with something like this:

B4X:
'Executes the query and fills the Spinner with the values in the first column
Sub ExecuteSpinner(Prompt as String, SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Spinner1 As Spinner)
    Spinner1.Clear
    Spinner1.Add(Prompt)
    Dim Table As List
    Table = ExecuteMemoryTable(SQL, Query, StringArgs, Limit)
    Dim Cols() As String
    For i = 0 To Table.Size - 1
        Cols = Table.Get(i)
        Spinner1.Add(Cols(0))
    Next
End Sub
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
I give up with getting Spinners to do what I want

Roger,

I never thought of changing DBUtils! The problem with the code change 'Spinner1.Add(Prompt)' that you suggested is that it then gives the user the option of selecting the Prompt. Though this could be disallowed (by checking that the selected item is not the first), it's confusing to the user. So I've changed the suggested 'Spinner1.Add(Prompt)' to 'Spinner1.Prompt=Prompt' in DBUtils, which - even though it still doesn't do what I want - at least has the merit of ExecuteSpinner setting the prompt rather than doing it before calling ExecuteSpinner and therefore appeals to my sense of pedantry! The real problem is that the Spinner view should have the feature of setting the Spinner's label to the prompt and showing it - but not allowing its selection - when the Spinner's label is clicked on.
PS in Gambas (an Object Oriented Visual Basic almost equivalent for PC Linux distros), the ComboBox does exactly what I want.
 
Last edited:
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
A couple other possibilities would be setting the current selection to -1 after loading the DB values. You could also process the selection changed event and not allow setting it to the first value either by setting it to -1 there or re-prompting the user with the selection list.

That annoyance and the drawing issues with the font size being weird in the control and not many options is why I made my own. It isn't really hard to make your own using a 9 Patch image in a label then just handling the click of the label and showing an Input List.

In my class I have all the methods for the combobox by each other so you could just grab those, the SetNinePatchDrawable function, the GetCharSize function, and the 9 patch images for the combo and you'd have your own combobox. Modify/Create a new ExecuteSpinner to return a List that you could pass to the AddCombobox function and you'd be in business.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
A couple other possibilities would be setting the current selection to -1 after loading the DB values. You could also process the selection changed event and not allow setting it to the first value either by setting it to -1 there or re-prompting the user with the selection list.

That annoyance and the drawing issues with the font size being weird in the control and not many options is why I made my own. It isn't really hard to make your own using a 9 Patch image in a label then just handling the click of the label and showing an Input List.

In my class I have all the methods for the combobox by each other so you could just grab those, the SetNinePatchDrawable function, the GetCharSize function, and the 9 patch images for the combo and you'd have your own combobox. Modify/Create a new ExecuteSpinner to return a List that you could pass to the AddCombobox function and you'd be in business.

Roger,
I have zero knowledge of Java. Also, I do not know what to do with the above functions in order to make a library or whatever I need to do.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
OK

Roger,

As I previously said, the real problem is that the Spinner view should have the feature of setting the Spinner's label to the prompt and showing it - but not allowing its selection - when the Spinner's label is clicked on. I've now achieved this by: using the existing spnCountry Spinner view by setting its Prompt to "", Add the "Select a Country" as the first entry on the Spinner's list, when "Select a Country" is selected by the user to effectively do nothing etc.
 
Upvote 0
Top