TonicArtos / StickyGridHeaders

This project has been superseded by SuperSLiM, a layout manager for RecyclerView. I strongly recommend using SuperSLiM and not StickyGridHeaders.
http://tonicartos.com
Apache License 2.0
1.47k stars 442 forks source link

Custom StickyGridHeadersBaseAdapter #39

Closed pavelkorolevxyz closed 11 years ago

pavelkorolevxyz commented 11 years ago

Hi I'm trying to implement my own StickyGridHeadersBaseAdapter, my current source code here - http://paste.org.ru/?11jrjh, and I use it like ModeAdapter adapter = new ModeAdapter(this); modeGridView.setAdapter(adapter);

Problems which I have is that 1) I have no idea how to call notifyDataSetChanged() for this adapter, so I can't change items 2) And implementation of AdapterView.OnItemClickListener (http://paste.org.ru/?mvgt7b) works strange Mode mode = (Mode) adapter.getItem(position); returns null for items with 1st and 2nd positions, item on 3rd position is actual 1st item in adapter. Where is my fault here? One more question is why I can't cast adapterView.getAdapter() in my OnItemClickListener to my "ModeAdapter" class. What if I want to call notifyDataSetChanged() here? I didn't find any examples for custom implementation of StickyGridHeadersBaseAdapter here.

Thanks in advance.

TonicArtos commented 11 years ago

There are some strange things with the adapters. I'll see about a better example, but for now you can look at the simple adapter version coupled with its wrapper.

The reason you aren't getting your adapter back out of the GridView is because it has been wrapped.

Now that it has been some time I think whole arrangement of the adapters and their wrappers needs to be looked at. On 11 Jul 2013 21:23, "King64rus" notifications@github.com wrote:

Hi I'm trying to implement my own StickyGridHeadersBaseAdapter, my current source code here - http://paste.org.ru/?11jrjh, and I use it like ModeAdapter adapter = new ModeAdapter(this); modeGridView.setAdapter(adapter);

Problems which I have is that 1) I have no idea how to call notifyDataSetChanged() for this adapter, so I can't change items 2) And implementation of AdapterView.OnItemClickListener ( http://paste.org.ru/?mvgt7b) works strange Mode mode = (Mode) adapter.getItem(position); returns null for items with 1st and 2nd positions, item on 3rd position is actual 1st item in adapter. Where is my fault here? One more question is why I can't cast adapterView.getAdapter() in my OnItemClickListener to my "ModeAdapter" class. What if I want to call notifyDataSetChanged() here? I didn't find any examples for custom implementation of StickyGridHeadersBaseAdapter here.

Thanks in advance.

— Reply to this email directly or view it on GitHubhttps://github.com/TonicArtos/StickyGridHeaders/issues/39 .

TonicArtos commented 11 years ago

Oh, I realise it has been some time, but here it is.

  1. You generally want to extend BaseAdapter when implementing your own Adapter. So your code should be
public class ModeAdapter extends BaseAdapter implements StickyGridHeadersBaseAdapter {
  1. Keep a reference to the adapter you put into setAdapter(...), the one you get from AdapterView<?>.getAdapter() isn't the one you put in.

There is no demonstration for the use of StickyGridHeadersBaseAdapter, however StickyGridHeadersSimpleAdapterWrapper is an implementation of BaseAdapter. It is in the source tree.