How to get the current item?
Opened this issue · 6 comments
Deleted user commented
How to get the position when the selection is complete?
DarkionAvey commented
I didn't include a method in the helper class to do that since there are many ways to achieve this with recyclerview.
For example (using the demo app, and assuming your items have the same height as yourRecyclerView):
int mScrolledDistance;
yourRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int position = mScrolledDistance/ yourRecyclerView.getHeight();
String value = ((DataAdapter) yourRecyclerView.getAdapter()).mData.get(position);
Log.e("TAG", "Current selection: " + position + " " + value);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
mScrolledDistance+= dy;
}
});
Deleted user commented
@DarkionAvey OK,Is the id in the snapToItem() in the helper class the current location, why not call it back?
DarkionAvey commented
@Anzhi-Meiying whoops! I actually forgot that part! I will create an interface to retrieve selected item position soon.
Deleted user commented
@DarkionAvey Thank you~
HunnyAroraH commented
Can i use this in my app >
DarkionAvey commented
Can i use this in my app >
Yes