truizlop / SectionedRecyclerView

An adapter to create Android RecyclerViews with sections, providing headers and footers.
806 stars 144 forks source link

Recycleview returns wrong index on click #13

Closed homedevs closed 8 years ago

homedevs commented 8 years ago

Hi,

I am using common available method to get recycleview items. I have noticed 2 things here.

  1. Why header is clickable ?
  2. I think due to header it calculates recycleview's first item as 2nd item.

What is solution ?

truizlop commented 8 years ago

Hi, Every cell might be clickable or not, it's up to the user of the library. Regarding the position, there is no such thing as first or second item in the context of the library. Positions are determined by a pair (section, row). If you have further comments, you need to provide more information on how you are using the library so that I can help.

homedevs commented 8 years ago

Thank you for the the response. I am trying to get position of particular item.

What exactly I want ,

I would like to have RV click listener which should return section index as well as position of item reside in the section.

Is there any way ?

Example,

consider this kind or RV :

https://github.com/truizlop/SectionedRecyclerView/blob/master/art/screenshot2.png

Now I would like to have position of Basket Match ,

Well , It should be SECTION 1, ITEM 0

truizlop commented 8 years ago

I think this is out of the scope of the library and something you can do. In the method onBindItemViewHolder(VH holder, int section, int position) you are supposed to bind the click listener to the view. At that point, you have access to section and position numbers, which you can keep track of.

homedevs commented 8 years ago

Thank you so much. Thats a perfect solution . Thank you.

shakdwipeea commented 7 years ago

Isn't that a bad idea? http://stackoverflow.com/a/33845951/3416786 How should I go about binding it in onCreateItemViewHolder

truizlop commented 7 years ago

You can still create a single click listener in onCreateItemViewHolder and pass section and position in onBindItemViewHolder