A super-common thing to do in Android is to take an array of objects and put it in a ListView. When making such a thing you would think that ArrayAdapter would be a nice easy way to do it.
But you would be wrong. Every time I've tried to use ArrayAdapter I ended up throwing it away and extending BaseAdapter.
The first problem you will hit is trying to figure out what the magical resource IDs you're supposed to feed into one of the 20 constructors.
Then you'll get caught trying to access an object that you need to get work done, like the inflater or the backing array. But they're all marked private without any getters. That's right, whoever designed this dumb class didn't think you needed to access the inflater or the array when inflating an array into views. So you end up using their dumb array access methods like getItem(int position). And if you need to do something like list.contains() you start writing ugly code until you realize you're being played for a sucker.
If you persist, you'll probably end up trying to figure out what a DropDownView is. Trying to understand what a non-existent ArrayFilter is. Desperately reading through this evil code wondering what you did wrong in your life to lead you to this point.
The moral is, just make your own BaseAdapter. It's not that hard and you won't end up hating your life.
No comments:
Post a Comment