25. 04. 2018
Rating bar works well in ListView in Android 4 and higher. You can scroll the list by swiping along X axis and change the RatingBar value by swiping along Y axis.
The problems comes on Android 2.X, here all touch events are consumed by RatingBar and it is not possible to scroll your list by touching the RatingBar and drag.
You can fix it by simply adding this listener to your RatingBars:
listenerRatingBar = new OnTouchListener() { float xDown; @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { // save down X coordinate xDown = event.getX(); } else if(event.getAction() == MotionEvent.ACTION_UP) { // if user moves do not move the finger, update RatingBar value if(Math.abs(xDown - event.getX()) < 5) { return false; } } return true; } }
Now simply add this listener to all your ratingbars in Adapters getView method:
ratingBar.setOnTouchListener(listenerRatingBar);
Voila, your ListView with RatingBars now works on Android 2.X.