[android-developers] Re: Custom BaseAdapter + dynamic updates = crash in ListView layout
The expandable lists are working out great, thanks! :^) If anyone down the line happens to know what's wrong with the original code above, though, I'd still appreciate understanding what it was doing incorrectly. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Custom BaseAdapter + dynamic updates = crash in ListView layout
On Tue, Feb 16, 2010 at 10:47 PM, whicken whic...@gmail.com wrote: Here's my GroupedListAdapter class, if that helps any - I added the getStableIds returning false in case there was any extra caching going on: Here's a question - what's the purpose of this adapter? What kind of layout / functionality are you trying to achieve? It looks to me like you're reproducing the ExpandablistList functionality in a very strange way. First suggestion would be to stick a break point in every single function and see what gets called and in what order. Also throw in some logging to make sure your logic is correct in each and every function. Beyond that I would strongly suggest reworking this class. Maybe take a look at BaseExpandableListAdapter instead of the BaseAdapter? Or at least create an object that represents a single header with some sections and delegate some of the functionality to it instead of maintaining two lists and trying to do the indexing yourself in the one class. That's bound to get confusing. - TreKing - Chicago transit tracking app for Android-powered devices http://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Custom BaseAdapter + dynamic updates = crash in ListView layout
I'm just trying to do a grouped layout - so a header would be followed by a bunch of rows, then another header, and another bunch of rows. They aren't collapsable, so I don't think it's quite an ExpandableList. As far as break points go, the only thing that seems to be called before the crash is getCount. I agree that the approach I've got here is all backwards, and I'm going to simplify it into a single class - if I just use the flat FancyAdapter (without the headers, naturally), then the crash goes away. So I think I'll just put support for alternate views into my flat adapter to support the headers, and toss the Grouped adapter for now. I would like to know why it's crashing, though, as I may bump into the problem again if I don't know what I was doing wrong in that code. Wendell On Feb 17, 1:55 am, TreKing treking...@gmail.com wrote: On Tue, Feb 16, 2010 at 10:47 PM, whicken whic...@gmail.com wrote: Here's my GroupedListAdapter class, if that helps any - I added the getStableIds returning false in case there was any extra caching going on: Here's a question - what's the purpose of this adapter? What kind of layout / functionality are you trying to achieve? It looks to me like you're reproducing the ExpandablistList functionality in a very strange way. First suggestion would be to stick a break point in every single function and see what gets called and in what order. Also throw in some logging to make sure your logic is correct in each and every function. Beyond that I would strongly suggest reworking this class. Maybe take a look at BaseExpandableListAdapter instead of the BaseAdapter? Or at least create an object that represents a single header with some sections and delegate some of the functionality to it instead of maintaining two lists and trying to do the indexing yourself in the one class. That's bound to get confusing. --- -- TreKing - Chicago transit tracking app for Android-powered deviceshttp://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Custom BaseAdapter + dynamic updates = crash in ListView layout
On Wed, Feb 17, 2010 at 8:34 AM, whicken whic...@gmail.com wrote: I'm just trying to do a grouped layout - so a header would be followed by a bunch of rows, then another header, and another bunch of rows. They aren't collapsable, so I don't think it's quite an ExpandableList. I would still recommend the ExpandableListAdapter since it matches your header + list of sections design. You can easily override the collapsing behavior and remove the default expanded / collapsed icon so it looks like a generic list. This gives you the benefit of reusing that class that's already provided to you, separating the header and section Views instead of having one giant view containing both, and makes it easier to support clicking on the header or individual sections. Plus the option to re-enable the collapse behavior if you decide you need it down the road. - TreKing - Chicago transit tracking app for Android-powered devices http://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Custom BaseAdapter + dynamic updates = crash in ListView layout
If I can believe the debugger, my getView function is never called between notifyDataSetChanged and the crash. The only calls to my adapter are three calls to getCount, which in my main test case happen to return 13. (There's a group of 7, and group of 4, and two headers). I had 24 entries before the reload method, so there are definitely less entries than before. Any other ideas where I can look? Would it help if I posted a larger example? Wendell On Feb 16, 11:35 am, TreKing treking...@gmail.com wrote: On Tue, Feb 16, 2010 at 1:54 AM, whicken whic...@gmail.com wrote: Any ideas where I should be looking? I would step through the getView() function in your custom adapter and see what indices it's trying to get at when it breaks and how many objects you actually have stored. That might give you more of a clue as to where you're going wrong. --- -- TreKing - Chicago transit tracking app for Android-powered deviceshttp://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Custom BaseAdapter + dynamic updates = crash in ListView layout
Here's my GroupedListAdapter class, if that helps any - I added the getStableIds returning false in case there was any extra caching going on: public class GroupedListAdapter extends BaseAdapter { ArrayAdapterString headers; ListAdapter sections; public GroupedListAdapter(Context context, int layout) { headers = new ArrayAdapterString(context, layout); sections = new ArrayListAdapter(); } public void addSection(String header, Adapter adapter) { headers.add(header); sections.add(adapter); } public void clear() { headers.clear(); sections.clear(); } public Object getItem(int position) { int ct = 0; for (Adapter section : sections) { int size = section.getCount() + 1; if (position == 0) return headers.getItem(ct); if (position size) return section.getItem(position - 1); position -= size; ++ct; } return null; } public int getCount() { int ct = headers.getCount(); for (Adapter section : sections) ct += section.getCount(); return ct; } public int getViewTypeCount() { int ct = 1; for (Adapter adapter : sections) ct += adapter.getViewTypeCount(); return ct; } public int getItemViewType(int position) { int type = 1; for (Adapter section : sections) { int size = section.getCount() + 1; if (position == 0) return 0; if (position size) return type + section.getItemViewType(position - 1); position -= size; type += section.getViewTypeCount(); } return -1; } public boolean hasStableIds() { return false; } public boolean areAllItemsSelectable() { return false; } public boolean isEnabled(int position) { return getItemViewType(position) != 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { int pos = 0; for (Adapter section : sections) { int size = section.getCount() + 1; if (position == 0) return headers.getView(pos, convertView, parent); if (position size) return section.getView(position - 1, convertView, parent); position -= size; pos++; } return null; } @Override public long getItemId(int position) { return position; } } And here's the general notion of the adapters I'm putting into the sections - the actual class has a more complicated view, but not by much (left and right text values). I know it needs to cache the view better, but I want to fix the crash/logic before putting in that optimization: class FancyAdapter extends ArrayAdapterOption { Activity context; ListOption options; FancyAdapter(Activity context, ListOption options) { super(context, R.layout.row, options); this.context = context; this.options = options; } public View getView(int position, View convertView, ViewGroup parent) { Option option = options.get(position); View row = View.inflate(context, R.layout.birow, null); TextView label = (TextView) row.findViewById(R.id.left); label.setText(option.toString()); return row; } } Any tips or advice is much appreciated. Wendell -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en