RatingBar onClick
Solution 1:
The reason for setOnClickListener()
not working is that RatingBar
overrides onTouchEvent()
(actually its super class, AbsSeekBar
, does) and never let View
take care of it, so View#performClick()
is never called (which would have called the OnClickListener
).
Two possible workarounds:
- derive from
RatingBar
and override onTouchEvent()
- use
OnTouchListener
instead, like so:
ratingBar.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { // TODO perform your action here } return true; }
In Kotlin
ratingBar.setOnTouchListener(View.OnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_UP) {
// TODO perform your action here
}
return@OnTouchListener true
})
HTH, Jonas
Solution 2:
Andrew, you can just try to use another event available for RatingBar, OnRatingBarChangeListener. See this example, it works for me!
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
viewMarketDetails(mContext);
dialog.dismiss();
}
});
So you don't need to use the onClickEvent but you have the same effect, but only work, off course, if you change actually the value. (If you click on the actual value, if has no effect)