WheelPicker
WheelPicker copied to clipboard
Get the new position while scrolling
Great library guys, only it lacks the possibility to get the new position while being scrolled. setOnWheelChangeListener is not enough, for it triggers only when switching between states. A useful listener would be a ChangingListener with onChanged method:
public interface OnWheelChangeListener {
public void onChanged(View wheel, int oldPosition, int newPosition) ;
}
Hello again, i came back to this library after a while and i see that setOnWheelChangeListener now contains three methods: onWheelScrollStateChanged(int state), onWheelSelected(int position) and finally the one i'm interested wit : onWheelScrolled(int offset), but still not enough; the offset parameter alone is practically useless, however i was able to add this lines to the library:
//changed the OnWheelChangeListener interface to look like this:
void onWheelScrolled(int offset, int position)
//and in the WheelPicker.java added this lines to onDraw method:
protected void onDraw(Canvas canvas) {
//get the position using the new mScrollOffsetY
int position = (-mScrollOffsetY / mItemHeight + mSelectedItemPosition) % mData.size();
position = position < 0 ? position + mData.size() : position;
//call the onWheelScrolled with both mScrollOffsetY for offset, and the new position
if (null != mOnWheelChangeListener)
mOnWheelChangeListener.onWheelScrolled(mScrollOffsetY, position);
.
.
.
}
Can you please add this to the library? @AigeStudio Thank you.
I think this might solve an issue I'm having where you can tap the scroll wheel while its in the middle of scrolling through a range and it gets caught in the middle between two selections. It would be nice to be able to snap to the nearest etc.