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 {
ArrayAdapter<String> headers;
List<Adapter> sections;
public GroupedListAdapter(Context context, int layout) {
headers = new ArrayAdapter<String>(context, layout);
sections = new ArrayList<Adapter>();
}
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 ArrayAdapter<Option> {
Activity context;
List<Option> options;
FancyAdapter(Activity context, List<Option> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en