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

Position in onItemClick is position + 1 row #53

Closed ayziaa closed 6 years ago

ayziaa commented 11 years ago

Inside "onItemClick(AdapterView<?> Grid_sdcard, View v, int position, long id) {}" I get the position plus one row, I"m guessing it's because the header takes on row. I would minus one row but I'm using android:numColumns="auto_fit" in my xml and the method to get the number of items in a row is only starting at API 16. What can I do to get the correct position?

TonicArtos commented 11 years ago

This is probably a bug, at the moment the position you are getting is relevant only to SGH. I guess, what should be happening, is that you should get the same position as you would expect from a normal GridView. On 3 Sep 2013 20:22, "ayziaa" notifications@github.com wrote:

Inside "onItemClick(AdapterView<?> Grid_sdcard, View v, int position, long id) {}" I get the position plus one row, I"m guessing it's because the header takes on row. I would minus on row but I'm using android:numColumns="auto_fit" in my xml and the method to get the number of items in a row is only starting at API 16. What can I do to get the correct position?

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

TonicArtos commented 11 years ago

Hi, could you please check that your problem is occurring in HEAD. Thanks.

ayziaa commented 11 years ago

I don't really know what that mean sorry. Le 26 sept. 2013 09:59, "Tonic Artos" notifications@github.com a écrit :

Hi, could you please check that your problem is occurring in HEAD. Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25149848 .

TonicArtos commented 11 years ago

Ah, can you please try using the latest code from the GitHub report and see if your problem still occurs. On 26 Sep 2013 20:02, "ayziaa" notifications@github.com wrote:

I don't really know what that mean sorry. Le 26 sept. 2013 09:59, "Tonic Artos" notifications@github.com a écrit :

Hi, could you please check that your problem is occurring in HEAD. Thanks.

— Reply to this email directly or view it on GitHub< https://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25149848>

.

— Reply to this email directly or view it on GitHubhttps://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25149984 .

ayziaa commented 11 years ago

Yes it seems to be working now!

2013/9/26 Tonic Artos notifications@github.com

Ah, can you please try using the latest code from the GitHub report and see if your problem still occurs. On 26 Sep 2013 20:02, "ayziaa" notifications@github.com wrote:

I don't really know what that mean sorry. Le 26 sept. 2013 09:59, "Tonic Artos" notifications@github.com a écrit :

Hi, could you please check that your problem is occurring in HEAD. Thanks.

— Reply to this email directly or view it on GitHub<

https://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25149848>

.

— Reply to this email directly or view it on GitHub< https://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25149984>

.

— Reply to this email directly or view it on GitHubhttps://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25166303 .

ayziaa commented 11 years ago

Well scratch my last message it's not working, position returned in the onClick is correct but using parent.getItemAtPosition(position) item returned is the one at the position minus one row.

2013/9/26 Audren Teissier audren.teissier@gmail.com

Yes it seems to be working now!

2013/9/26 Tonic Artos notifications@github.com

Ah, can you please try using the latest code from the GitHub report and see if your problem still occurs. On 26 Sep 2013 20:02, "ayziaa" notifications@github.com wrote:

I don't really know what that mean sorry. Le 26 sept. 2013 09:59, "Tonic Artos" notifications@github.com a écrit :

Hi, could you please check that your problem is occurring in HEAD. Thanks.

— Reply to this email directly or view it on GitHub<

https://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25149848>

.

— Reply to this email directly or view it on GitHub< https://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25149984>

.

— Reply to this email directly or view it on GitHubhttps://github.com/TonicArtos/StickyGridHeaders/issues/53#issuecomment-25166303 .

kyleparker commented 10 years ago

I'd like to +1 this issue... I'm using the latest version from GitHub and cannot seem to get the position/selected item to work as I need it.

The adapter position doesn't correlate to the GridView position - although in a way, it does. In this setup:

[ GRID HEADER #1] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
[ GRID HEADER #2] [11] [12] [13] [14] [15] [16]

I get the following info:

Click Item 1 adapter position = 0 gridview item checked position = 3

Click item 2 adapter position = 1 gridview item checked position = 4

Click Item 11 adapter position = 10 gridview position = 18

Is there a way to have the gridview position actually return/correspond to the correct value without having to resort to inspecting the items to determine A) blank items and B) grid headers? 18 makes sense - Item 10 is position 12, add 2 for the empty items on the same row, add 3 for the column span of the header. Then that makes the 1st row of header 2, grid position 18.

As a note - where this becomes an issue is using a viewpager and the gridview on the same screen - like on a tablet. The ViewPager is unable to set the appropriate selection in the gridview because the position does not match. Another use case is when using a tablet - gridview on screen 1, select item, go to screen 2, that same gridview appears and attempting to select the item.

I'm going to attempt the logic in the adapter, so any pointers, thoughts or alternatives would be appreciated!

xifan-xf commented 10 years ago

has the same problem at onItemLongClick using parent.getItemAtPosition(position) when position is 1.it's correct but in my StickyGridAdapter : @Override public Object getItem(int position) { return list.get(position); } position is -3 and app crash...