findViewbyID - How to Find a RatingBar using ID

findViewbyId was added in API Level 1
findViewById: Look for a child RatingBar with the given id. If this view has a given id, return this RatingBar. The findViewById() method is available to all activities in Android. findViewById allows you to find a view inside an activity layout.

1. Name a RatingBar, in XML named myRatingBar.

2. Declare a RatingBar named myRatingBar.

3. In MainActivity, java file, add the below code to the onCreate method. Where R.id.myRatingBar is the same as the android:id name in your main.xml file, and myRatingBar is the RatingBar name referred to in Java. This returns a RatingBar class and is casted to a RatingBar type so you can work with it.

myRatingBar = (RatingBar) findViewById(R.id.myRatingBar); 

4. Compile and run!

Resources: