# StarRating

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/StarRating.java+class:androidx.media3.common.StarRating)

*** ** * ** ***


```
public final class StarRating extends Rating
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.media3.common.Rating](https://developer.android.com/reference/androidx/media3/common/Rating) ||
|   | ↳ | [androidx.media3.common.StarRating](https://developer.android.com/reference/androidx/media3/common/StarRating) |

*** ** * ** ***

A rating expressed as a fractional number of stars.

## Summary

| ### Public fields |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int` | `https://developer.android.com/reference/androidx/media3/common/StarRating#maxStars()` |
| `final float` | `https://developer.android.com/reference/androidx/media3/common/StarRating#starRating()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/StarRating#StarRating(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int maxStars)` Creates a unrated instance with `maxStars`. |
| `https://developer.android.com/reference/androidx/media3/common/StarRating#StarRating(int,float)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int maxStars, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float starRating )` Creates a rated instance with `maxStars` and the given fractional number of stars. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/StarRating#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html obj)` |
| `static https://developer.android.com/reference/androidx/media3/common/StarRating` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/StarRating#fromBundle(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html bundle)` Restores a `StarRating` from a `https://developer.android.com/reference/android/os/Bundle.html`. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int` | `https://developer.android.com/reference/androidx/media3/common/StarRating#getMaxStars()()` Returns the maximum number of stars. |
| `float` | `https://developer.android.com/reference/androidx/media3/common/StarRating#getStarRating()()` Returns the fractional number of stars of this rating. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/StarRating#hashCode()()` |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/StarRating#isRated()()` Whether the rating exists or not. |
| `https://developer.android.com/reference/android/os/Bundle.html` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/StarRating#toBundle()()` Returns a `https://developer.android.com/reference/android/os/Bundle.html` representing the information stored in this rating. |

| ### Inherited methods |
|---|
| From [androidx.media3.common.Rating](https://developer.android.com/reference/androidx/media3/common/Rating) |---|---| | `static https://developer.android.com/reference/androidx/media3/common/Rating` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/Rating#fromBundle(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html bundle)` Restores a `Rating` from a `https://developer.android.com/reference/android/os/Bundle.html`. | |

## Public fields

### maxStars

```
public final @IntRange(from = 1) int maxStars
```

### starRating

```
public final float starRating
```

## Public constructors

### StarRating

```
public StarRating(@IntRange(from = 1) int maxStars)
```

Creates a unrated instance with `maxStars`. If `maxStars` is not a positive integer, it will throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int maxStars` | The maximum number of stars this rating can have. |

### StarRating

```
public StarRating(
    @IntRange(from = 1) int maxStars,
    @FloatRange(from = 0.0) float starRating
)
```

Creates a rated instance with `maxStars` and the given fractional number of stars. Non-integer values may be used to represent an average rating value. If `maxStars` is not a positive integer or `starRating` is out of range, it will throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int maxStars` | The maximum number of stars this rating can have. |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float starRating` | A fractional number of stars of this rating from `0f` to ` maxStars`. |

## Public methods

### equals

```
public boolean equals(@Nullable Object obj)
```

### fromBundle

```
@UnstableApi
public static StarRating fromBundle(Bundle bundle)
```

Restores a `StarRating` from a `https://developer.android.com/reference/android/os/Bundle.html`.

### getMaxStars

```
public @IntRange(from = 1) int getMaxStars()
```

Returns the maximum number of stars. Must be a positive number.

### getStarRating

```
public float getStarRating()
```

Returns the fractional number of stars of this rating. Will range from `0f` to `https://developer.android.com/reference/androidx/media3/common/StarRating#maxStars()`, or `https://developer.android.com/reference/androidx/media3/common/Rating#RATING_UNSET()` if unrated.

### hashCode

```
public int hashCode()
```

### isRated

```
public boolean isRated()
```

Whether the rating exists or not.

### toBundle

```
@UnstableApi
public Bundle toBundle()
```

Returns a `https://developer.android.com/reference/android/os/Bundle.html` representing the information stored in this rating.