我的问题是当我再次评价相同的值时,它第二次没有响应。这意味着当我第一次评价“4”时,我第二次不能评价为“4” ..它仅在我评价其他值而不是“4”时才会响应。
这是我尝试过的(我需要getRatingBar
在我的代码中执行操作)。
public class InteractiveRatingBarActivity extends Activity implements
OnRatingBarChangeListener {
RatingBar getRatingBar;
RatingBar setRatingBar;
TextView countText;
int count;
float curRate;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewsById();
setRatingBar.setRating(curRate);//overall rating
getRatingBar.setOnRatingBarChangeListener(this);// ratingbar for user action.
}
private void findViewsById() {
getRatingBar = (RatingBar) findViewById(R.id.getRating);
setRatingBar = (RatingBar) findViewById(R.id.setRating);
countText = (TextView) findViewById(R.id.countText);
}
public void onRatingChanged(RatingBar rateBar, float rating,
boolean fromUser) {
DecimalFormat decimalFormat = new DecimalFormat("#.#");
curRate = Float.valueOf(decimalFormat.format((curRate * count + rating)
/ ++count));
Toast.makeText(InteractiveRatingBarActivity.this,
"New Rating: " + curRate, Toast.LENGTH_SHORT).show();
setRatingBar.setRating(curRate);
countText.setText(count + " Ratings");
}
}
提前致谢