title: How to use the RatingBar in Android properly?
body: <p>Need some help with implementing/understanding how the RatingBar works.</p>
  
  <p>In my Activity I inflate my xml which has a RatingBar in it multiple times. Something like this. Stripped out version is </p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  View contentView = getLayoutInflater().inflate(R.layout.activity_main, null);
  setContentView(contentView);
  // there are other views here sooo had to do it this way.
  ViewGroup ratingsContainer = (ViewGroup) findViewById(R.id.x11);
  for(int i = 0 ; i &lt; 5; i++){
      ratingsContainer.addView(createRatingBar(i)); 
  }
  }
  
  private RatingBar createRatingBar(int index){
      RatingBar ratingBar = (RatingBar)getLayoutInflater().inflate(R.layout.ratingbar, null);
      ratingBar.setRating(index);
      return ratingBar;
  }
  </code></pre>
  
  <p>My ratingbar xml</p>
  
  <pre><code>&lt;RatingBar xmlns:android="http://schemas.android.com/apk/res/android"
                  style="?android:attr/ratingBarStyleSmall"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical"
                  android:numStars="5"
                  android:stepSize="1"/&gt;
  </code></pre>
  
  <p>my activity_main</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      &gt;
  &lt;LinearLayout 
      android:id="@+id/x11"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      &gt;
      &lt;/LinearLayout&gt;    
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But it does not seem to work properly
  1. The number of stars it shows is more than the number of stars. More than 5
  2. The data does not hold on rotation.</p>
  
  <p>What do you think might be the problem?</p>