I’ve been sick lately which interferes with the motivation to do much of anything, so while progress has been slow I have been plugging along little by little. Today I finished writing and debugging yet another activity with about a half dozen left to go. If I ever modify this to work on smaller form factor devices there will be even more activities as many of these consist of multiple fragments (the one I was working on today used three fragments). I worry that I’m perhaps making things a little bit too complex with all of these different activities, but I think that as long as the functionality is exposed in an obvious fashion everything should be fine. I might put some feelers out to see if anybody else using Typica has an Android 3+ tablet and runs the sort of business that this app would be useful in and see if I can get some feedback once 1.0 is finished.
1. The example code that I’ve seen on the use of the Spinner widget all use an ArrayAdapter<CharSequence> created through a call to ArrayAdapter.createFromResource(). This works fine when dealing with a pre-determined set of values, but doesn’t work so well if the values are coming from a database query. Calls to add() throw an UnsupportedOperationException. The solution is to create the object with one of the many available constructors instead. For example:
new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_dropdown_item, new ArrayList<CharSequence>())
This results in the adapter using a proper list type (which supports add and remove operations) internally which is apparently not the case when using createFromResource().
2. Code analysis in Eclipse doesn’t always provide the most helpful message for diagnosing errors. Today I had an inner class object (a listener) where the bulk of the required functionality was needed in another function as well, so I took the stuff common to both and wrote that in a private (outer) class method. The inner class method would call out to that, but the message I got seemed to indicate that I couldn’t do that. I, still not completely fluent in Java, thought, “really? I thought I could do that,” quick Googling to find that indeed I should be able to do that. The true problem, which the error message provided no hint to, was that I had just left off the return type specifier for the function I was trying to call. Oops. Simple mistake to fix, I didn’t spend that much time figuring out where my error was, and I didn’t resort to just having the same code in there twice.