a) main.xml
b) ratingActivity.java
The code is as follows
a) main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RatingBar
android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars = "5"
android:stepSize="1.0"
/>
</LinearLayout>
b) ratingActivity.java
package org.example.rating;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.Toast;
import android.widget.RatingBar.OnRatingBarChangeListener;
public class ratingActivity extends Activity implements OnRatingBarChangeListener{
RatingBar rb;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rb = (RatingBar)findViewById(R.id.ratingbar);
rb.setOnRatingBarChangeListener(this);
}
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
int ratedStars = (int) rating;
Toast.makeText(this, "Rating star count is "+ratedStars, Toast.LENGTH_SHORT).show();
}
}
Screenshot :

worth full to me
ReplyDelete