B4A Library [Library] Data Bound Spinner

May be of use to someone but posted more to gather some feedback about what features people would like to see in a set of data bound views.

The DBSpinner adds the following methods to the vanilla Spinner:

SetDatabase(DB As SQL): Set the database connection to use.

SetRowSource(SelectStatement AS String): Sets the SQL SELECT statement that will populate the Spinner

GetRowSource(): Returns the SELECT statement.

Requery(): Clears the spinner and populates it with the result of SELECT statement specified in SetRowSource()
 

Attachments

  • dbcontrols.zip
    104.9 KB · Views: 563

Mahares

Expert
Licensed User
Longtime User
Nice library. It reminds me of Microsoft Access. It would be really nice if you can include more than one column in the SetRowSource and then have the ability to return one of the columns when clicked. Something like this:
B4X:
 myDBSpinner.SetRowSource("SELECT SKU, SHRT_DESC  FROM PARTLIST ORDER BY SHRT_DESC ")
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
That was another thing I needed was an ID associated with Text (Also in my View Manager Class implementation). I've actually started converting it to a B4A Library (About 25% complete) and I can't really find a way to make Spinners store things like that. I'd really like to use the standard spinner since in a library, but it may be too limited. I did see that Spinners have two modes (Dialog and Dropdown) which I didn't know of and would be a nice addition to B4A.
 

grant1842

Active Member
Licensed User
Longtime User
Thanks for your work . I think dbaware views are great.
 

keirS

Well-Known Member
Licensed User
Longtime User
Nice library. It reminds me of Microsoft Access. It would be really nice if you can include more than one column in the SetRowSource and then have the ability to return one of the columns when clicked. Something like this:
B4X:
 myDBSpinner.SetRowSource("SELECT SKU, SHRT_DESC  FROM PARTLIST ORDER BY SHRT_DESC ")

You can do that. In the example if you change the RowSource to:

B4X:
myDBSpinner.SetRowSource("SELECT SKU,SHRT_DESC FROM PARTLIST ORDER BY SKU")

And the ItemClick to:

B4X:
Sub Spin_ItemClick(Position As Int, Value As Object)
    Dim getCursor As Cursor
    getCursor = myDBSpinner.GetCursor()
   getCursor.Position = Position
   
    ToastMessageShow("Description = " & getCursor.GetString("SHRT_DESC"),False)
 End Sub

You can get the SHRT_DESC field. The Spinner just populates itself with the first column in the cursor and ignores the others.
 

Mahares

Expert
Licensed User
Longtime User
Thanks KeirS. Selecting the correct column works well. The only drawback is: When you select more than one column in the rowsource, only one column displays when the spinner is displayed.
 

keirS

Well-Known Member
Licensed User
Longtime User
Yes. The spinner is just an extension of the one provided in B4A. While it is possible to have multi-column spinners in Android (and I may look at it in the future) I want to concentrate on getting a collection of data bound views based on the existing ones available in B4A before looking at anything else.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
So, the Cursor persists as long as the view? When I was reading about setting a cursor for an AutoComplete EditText it seemed to indicate that you needed to monitor events and create the cursor when the listview was opened/requested and close the cursor when the listview was closed/dismissed otherwise there would be a leak. In my class that I'm now building my library from I had used a cursor to read DB values and Save/Restore State of views, but a List of Types for the Spinner values (It was built using a cursor, but the cursor was closed after built).

I also had a lot of issues with SQL connections closing on me and/or the variables getting deleted even when Process Globals. I ended up making everything used as needed to populate a static list and closed after use.
 

keirS

Well-Known Member
Licensed User
Longtime User
Yes it persists. Never seen the issues you describe. This may well be to do with the environment my Apps are used in. Tablets where they are quite heavily locked down and some even locked down with pseudio kiosk mode. I will do some serious stress testing and see what happens.
 

sellnet

New Member
Licensed User
Longtime User
DBSpinner crashing

May be of use to someone but posted more to gather some feedback about what features people would like to see in a set of data bound views.

The DBSpinner adds the following methods to the vanilla Spinner:

SetDatabase(DB As SQL): Set the database connection to use.

SetRowSource(SelectStatement AS String): Sets the SQL SELECT statement that will populate the Spinner

GetRowSource(): Returns the SELECT statement.

Requery(): Clears the spinner and populates it with the result of SELECT statement specified in SetRowSource()

This library is exactly what I need. However, it simply won't run for me.
The sample app you provided crashes as soon as I open it.
I can get your spinner to appear on activities in my app, but they are not populated and as soon as I try to click on them, the app crashes.

I am using B4A 2.00 and testing on a Samsung Galaxy S3 with running 4.1.1

Any ideas?
 

ikidd

Member
Licensed User
Longtime User
I get this when I click on the spinner. It seems to populate and work with the buttons in the demo, but touch the spinner and it crashes and logcats:

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

I'm thinking it's not instantiating the control correctly.
 

Sannie72

Member
Licensed User
Longtime User
Spinner works fine, I need the second datafield, so this is great! However, my app is in Holo.light, the dbspinner is holo dark (white chars on dark background). The result is unuseable (does not look very professional). When I change .color and .textcolor properties, the spinner itself changes (although the bottom right triangle indicating a spinner is invisible) but the list with values is still holo.dark theme.
Any suggestions?
(running B4A 3.20 BETA 1 on Galaxy S3, 4.3)
 

keirS

Well-Known Member
Licensed User
Longtime User
The spinner is just an wrapper of the standard B4A spinner class. I will rebuild the library with the latest B4A libraries and see if that solves the problem.
Sorry for not replying to other peoples issues but I have only just back to developing in B4A. Been to busy with other projects to do any Android stuff. Now have a big Android project on the go so will hopefully be releasing a few bits and pieces.
 
Top