I am trying to use a RatingBar like this.
private RatingBar ratingBar;
TextView submitTv;
int rate;
public RateDialog(){
rate = 0;
}
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.dialog_rate, null);
builder.setView(v);
ratingBar = (RatingBar)v.findViewById(R.id.ratingbar);
submitTv = (TextView)v.findViewById(R.id.rate_textview_submit);
submitTv.setOnClickListener(this);
ratingBar.setOnRatingBarChangeListener(this);
return builder.create();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.rate_textview_submit:
sendResult(INT_RATING_CODE,rate );
getDialog().dismiss();
break;
}
}
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
//rate = (int)rating;
rate = (int) ratingBar.getRating();
Toast.makeText(getActivity(),""+String.valueOf(rate),Toast.LENGTH_SHORT).show();
}
and the xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="150dp">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingbar"
android:numStars="5"
android:gravity="center"
android:layout_gravity="center"
android:isIndicator="true"
android:stepSize="1.0"
android:rating="2.0"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/dark_grey_transparent" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Submit"
android:textSize="18sp"
android:textStyle="normal"
android:textColor="@color/orange"
android:background="@drawable/grey_semitransparent"
android:gravity="center"
android:id="@+id/rate_textview_submit" />
</LinearLayout>
However, I can't get the RatingBar to respond to inputs.Even after trying to use the toast in onRatingChanged() the toast does not fire.Where am I going wrong?
This should be false.