Hi,
I am implementing a RatingBar in an AlertDialog, but I am not able to
implement rating using it.

I have tried RatingBar.setOnRatingBarChangeListener(), but that isn't
creating any listener events.

I am posting a code snippet below which shows how I have implemented
RatingBar in an AlertDialog. RatingBar is created in an xml file called
ratingalertdialog.xml.

                AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
 LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.ratingalertdialog,
                               (ViewGroup) findViewById(R.id.layout_root));
builder = new AlertDialog.Builder(this);
 builder.setView(layout);

                RatingBar rB = (RatingBar)findViewById(R.id.Rating01);
 rB.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
 @Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// TODO Auto-generated method stub
Log.i("rating bar","change listener");
}
});
                alertDialog = builder.create(); alertDialog.show();

ratingalertdialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
android:id="@+id/layout_root" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
 android:layout_marginBottom="25px">

<TextView android:id="@+id/text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#FFF"
android:text="Rate this video" android:layout_gravity="center_horizontal" />


<RatingBar android:id="@+id/Rating01" android:layout_width="wrap_content"
android:visibility="visible" android:clickable="true"
android:drawingCacheQuality="low" android:paddingTop="5px"
android:numStars="5" android:layout_gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true" android:layout_height="fill_parent"
style="?android:attr/ratingBarStyle" android:scrollbarSize="10px"
android:stepSize="0.5">
</RatingBar>
</LinearLayout>

The above snippet runs fine, but there is no listener activity.

How to implement the RatingBar onClickEvent in the AlertDialog? Do I need to
implement some other listeners to make it work?

Thanks
Ashok

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to