RatingBar onClick

后端 未结 5 879
孤街浪徒
孤街浪徒 2020-12-25 13:59

I have a ListView that uses different XML files to create Views and make items out of. One of these XML files contains a RatingBar. Everything displays and looks excellent

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 14:26

    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;
          }
      

    HTH, Jonas

提交回复
热议问题