Month: July 2012

It’s not a bug. It’s a feature.

I like Android development. But you go off the beaten path and, well …

I’ve written some custom ListView objects that get rendered depending on what kind of device is needed for a home automation app I’m working on.

So far so bad.

Now you need to be able to turn that device on or off.

Tricky.

On the phone’s screen there is a button for every item displayed, each showing the correct value. 

BUT … inside it reuses the object that has been created. I have attached listeners to the button that mean when you toggle it off or on it sends a message to the underlying device.

It does. But then it sends messages to ALL the devices of the same type, because I’ve attached the listeners to what is basically the same GUI over and over again. So it looks right on the screen, but underneath all that happened was things were set in the right order so they display correctly. Right at the end of the call chain it sets the value back just for fun.

OK – let’s get it to tell me the ID of whichever row was tapped and only allow commands to be sent to that device. Nope. The button has the focus and won’t tell it’s container there was a tap and I’ve tried all the suggestions google could find for me. So the listener doesn’t ever get fired.

I think I’m going to have to short circuit the views and create them by hand, so each is a separate object with its own button etc. defined with its own listeners.

List View is designed to work with thousands of elements of homogenous data that can be tapped on and treated as a unit. But actually, for the case where there’s only a few that might have other things on them, it just doesn’t work.

I’ll have another look on line tomorrow.

By the way – I’d lay money that iOS Table View has similar problems, before people start doing the fanboi thing.

Take what the defence gives you – coding

I’ve recently listened to Steven Pressfield’s Turning Pro about 10 times driving up and down the motorways. I can’t recommend it highly enough. One of the things he talks about are the things that get in the way of getting things done, of pursing your art and doing what you have to do when you turn pro.

So, some days you just can’t get your mojo on. The pro doesn’t let this stop the work happening. So you take whatever you can get today and work with it. In sporting terms you’re having a day where you can’t make progress against your opponent. So you take what the defence gives you and push on. 

So when you look at what you need to get written today and don’t know how to start do the little things you can do and let the ideas percolate through your head. This is similar to the technique where writers just start writing anything that comes into their heads. When you do this it gets you moving and when you are moving you are not stuck any more.

So take what the defence gives you, take the steps you can take. You can’t do the big stuff all the time. But keep moving, that’s what works.