Android Project:
Rating Bar(For Beginers):
MainActivity.java
package
com.sattar.ratingbar;
import
android.os.Bundle;
import
android.app.Activity;
import
android.view.Menu;
import
android.widget.RatingBar;
import
android.widget.RatingBar.OnRatingBarChangeListener;
import
android.widget.Toast;
public
class MainActivity extends Activity {
public RatingBar ratingBar;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ratingBar = (RatingBar)
findViewById(R.id.ratingBar1);
ratingBar.setOnRatingBarChangeListener(new
OnRatingBarChangeListener() {
public void
onRatingChanged(RatingBar ratingBar, float rating,
boolean
fromUser) {
//
TODO Auto-generated method stub
Toast.makeText(MainActivity.this,
"Your Rating is: " + rating,
Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the menu;
this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main,
menu);
return true;
}
}
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="180dp"
android:numStars="8"
android:stepSize="1.0" />
</RelativeLayout>