B4i Library [class] Spinner

I wrote this class to try to simplify porting a B4A app to B4i. The app uses Spinners, and I was frustrated by the lack of a suitable replacement. I tried Pickers, but they take up too much space. Also, a lot of fiddly changes/conditional compilation is required to handle differences between B4A and B4i, in particular differences in trivial things like the way you set the text size.

So, I wrote this class to mimic the B4A Spinner programming interface and hide a lot of the differences between B4a and B4i, thus reducing the number of changes/conditional compilation required. It's a CustomView, so can be set up in the Designer or created programmatically. The attached sample project contains examples of both.

Internally it's implemented as a Label which when clicked displays an action sheet for the user to make their selection.

The class expects the same _ItemClick callback as the B4A Spinner, and implements all of the B4A Spinner methods EXCEPT for the following:
  • Background
  • DropdownBackgroundColor
  • DropdownTextColor
  • Invalidate
  • Invalidate2
  • Invalidate3
  • Prompt
  • SetBackgroundImage
  • SetColorAnimated
  • SetVisibleAnimated
The following methods have been added:
  • SetCallbackModule - By default the class assumes that the callback routine is in the Main module. If it isn't you must call SetCallbackModule to set the module it is in. eg spr.SetCallbackModule(Me)
  • View - returns the underlying Label used in the Spinner class. Useful for changing it's attributes directly
  • GetBase - if the Spinner was created in the Designer then this returns the Base Panel containing the Spinner. If the Spinner was created programmatically then this return the underlying Label used in the Spinner class. Useful for adding the Spinner to a parent view. eg:
B4X:
myPanel.Addview (spr.GetBase, 0, 0, 20, 10)
  • SetBorder - Set the border of the underlying label
  • TextAlignment - attribute to get/set the alignment of the text in the underlying label.
I hope this is of some use.

Hugh

2015-12-08 Updated with V0.10
2016-04-20 Updated with V0.11
2016-07-06 Updated with V0.20
 

Attachments

  • Spinner0.20.zip
    6.8 KB · Views: 140
Last edited:

Hugh Thomas

Member
Licensed User
Longtime User
When I first wrote this class I couldn't find any easy way to implement the "Prompt" feature, so I left it as unsupported. I considered displaying a label with the prompt in it before invoking the Action Sheet, but the problem is making sure it doesn't get covered by the Action Sheet list. If someone can suggest a way of adding the prompt feature then I'm happy to reconsider.

Hugh
 
Top