Monday, April 2, 2012
Android ListViews in Tablet Fragments
I fell foul of a number of issues, several of which I have encountered before and one might have hoped I wouldn't have been tripped by them again. They include
1) need for embedded ListViews to have special IDs
2) nature of ArrayAdapters
3) variations arising from fragments
One of the early errors that slowed me down and forced me to create a separate FavesFragment to handle the list in isolation was the "inflating fragment error" The following StackOverflow posts helped orient me ...
I spent a lot of time thinking that an AsyncTask was going to be necessary in order to enable the listview data to be updated (e.g. add more rows), but that turned out not to be the case. The key trick there was to do any addition to the data through ArrayAdapter.add, and basically forget about any reference to the initial data passed to ArrayAdapter - ultimately I just initialized with an empty ArrayList. There were several confusing StackOverflow posts that deflected me from ultimately finding salvation in the android irc channel on freenode.net
Well this second one should have helped me more, but I was trying to do much at once, as well as programming Pythonically in Java, which often gets me into trouble ...
And I think this android developer blog got me a bit further:
but annoyingly it was like much of the android docs; code fragments, but not an actual working system. Ultimately it was IRC that sorted me out, with other developers pointing out that the key issue was updating the data through the ArrayAdapter itself.
I also burnt time seeing if I could get some simple persistence going with Preferences, but it seemed that unlike in iOS, I couldn't store any more than a simple set of Strings in light weight preferences, which wasn't quite sufficient for the stack object I was working with, or maybe it would have been okay? Hmm ....