Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single star RatingBar

Tags:

android

I'm trying to display a RatingBar View that is only capable of showing a one star rating, or no stars. This seems so trivial...

My ratingbar is defined like so:

My view implements OnRatingBarChangeListener and OnTouchListener

My OnRatingBarChange handler has no code. My OnTouch handler looks like so:

@Override
public boolean onTouch(View v, MotionEvent event)
{
    if(event.getAction() == MotionEvent.ACTION_DOWN)
    {
        if(this.mRating.getRating() == 0)
        {
            this.mRating.setRating(1);
        }
        else
        {
            this.mRating.setRating(0);
        }
        return true;
    }
    return false;
}

No matter what, the onTouch event does not succeed at setting the rating back to zero. This seems way too trivial. What am I doing wrong?

Thanks!

like image 416
Aaron Hudon Avatar asked Dec 10 '22 13:12

Aaron Hudon


1 Answers

Consider using ToggleButton and btn_star stock drawable instead. Here's example:

    <ToggleButton
        android:button="@android:drawable/btn_star"
        android:background="@android:color/transparent"
        android:textOn=""
        android:textOff=""
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
like image 168
Pēteris Caune Avatar answered Dec 12 '22 03:12

Pēteris Caune