Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ratingbar doesn't update
    primarykey
    data
    text
    <p>I've made a ratingbar in my app which uses a custom style, using my own stars.</p> <p>My ratingbar is defined as followed:</p> <pre><code> &lt;RatingBar android:layout_width="wrap_content" android:layout_height="15dp" android:id="@+id/ratingBar" android:numStars="10" android:stepSize="1" android:rating="10" android:layout_marginTop="5dp" android:layout_below="@id/feedbackTable" android:layout_toRightOf="@id/ratingText" android:layout_marginLeft="5dp" style="@style/starBar" /&gt; </code></pre> <p>The style that I use in styles.xml is:</p> <pre><code>&lt;style name="starBar" parent="@android:style/Widget.RatingBar"&gt; &lt;item name="android:progressDrawable"&gt;@drawable/ratingstars&lt;/item&gt; &lt;item name="android:minHeight"&gt;22dip&lt;/item&gt; &lt;item name="android:maxHeight"&gt;22dip&lt;/item&gt; &lt;/style&gt; </code></pre> <p>With ratingstars.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/background" android:drawable="@drawable/ratingstars_full_empty" /&gt; &lt;item android:id="@+id/secondaryProgress" android:drawable="@drawable/ratingstars_full_empty" /&gt; &lt;item android:id="@+id/progress" android:drawable="@drawable/ratingstars_full_filled" /&gt; &lt;/layer-list&gt; </code></pre> <p>When I adjust the android:rating it shows the correct amount of stars filled and being empty in the preview. However, using my emulator or real device the bar stays completely filled with stars (10/10). I've tried adjusting it programmatically by using the following piece of code:</p> <pre><code> ratingbar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { Log.d("rating", rating+""); ratingbar.setRating(rating); } }); </code></pre> <p>Now the log from logcat shows actually that rating IS changed, but the bar does not visually update itself with e.g. 6 stars being full, and 4 empty and I have no clue why.</p> <p>The drawables are correct as the preview also shows it correct, so what can cause this?</p> <p><strong>Edit:</strong></p> <p>This is ratingstars_full_filled.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:state_window_focused="true" android:drawable="@drawable/star" /&gt; &lt;item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/star" /&gt; &lt;item android:state_selected="true" android:state_window_focused="true" android:drawable="@drawable/star" /&gt; &lt;item android:drawable="@drawable/star" /&gt; &lt;/selector&gt; </code></pre> <p>And here is ratingstars_full_empty.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:state_window_focused="true" android:drawable="@drawable/star_empty" /&gt; &lt;item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/star_empty" /&gt; &lt;item android:state_selected="true" android:state_window_focused="true" android:drawable="@drawable/star_empty" /&gt; &lt;item android:drawable="@drawable/star_empty" /&gt; &lt;/selector&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload