brain food, good buy, futzing with Gallery

Found Beer Planet yesterday morning, now I have a lot more reading to do.

I bought this Compaq nx 7400 laptop from Craigslist earlier this month just so I’d have something to take to meetups and use the Android SDK on. Didn’t realize it would become my favorite device in the house – seems I’m valuing flexibility and comfort over even the allure of dual monitors. Anyway, a damn good investment at $150.

I thought I’d try creating a little app that displays/demonstrates all of the android.R resources – I mean how do you know what an icon or layout will look like until you try it in an app? So, starting with a gallery of android.R.drawable – should be pretty easy, right? Hahahah. Funny, not a lot of info on the dev guide about Gallery, and following the examples got me a big fat ClassCastException about Gallery$LayoutParams. Geez I hate that thing. There’s no way to relate it back to what I actually did wrong. *sigh*

BTW I created a custom adapter (just extend BaseAdapter) so I could use reflection on android.R.drawable and turn all of the fields into items for the gallery (field value for image resource ID and field name for caption) – that way I don’t need to make a long list and any variation between platforms is captured automatically. I thought that was pretty clever and it’s really not very hard, except for this business of filling in the view.

An initial glance at Gallery reference doc indicates maybe I should try using a simple ImageView as the gallery item just to get going – the Gallery.LayoutParams need to be applied to the Gallery item, but currently my item is actually a LinearLayout holding the image and a caption TextView. That seems to “fix” the ClassCast problem but I’m only seeing one item, no scrolling. How does this Gallery thing work? Time to google… oh wait, there is a Gallery tutorial in the dev guide after all. Durrr. But! I try to use this code:

TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
mGalleryItemBackground = a.getResourceId(
        android.R.styleable.Theme_galleryItemBackground, 0);
a.recycle();

… and now Eclipse tells me there’s no such thing as android.R.styleable – example fail! WTF? NOW it’s time to google. That doesn’t help; looking at the APIDemos examples, I notice that for 1.5 it used its own R.styleable and not android.R.styleable, so maybe the latter didn’t come into existence until a later API level. The class reference helpfully doesn’t say. And I need to stop here for today :-(

Advertisements