我是安卓新手,我在我的应用程序中使用了RatingBar,现在我想根据RatingBar中的明星选择来计算评分。我在我的应用程序中使用了: num_of_rating = rating.getRating();,但我无法获得它的数量。如果有人知道答案,请给我答案。
发布于 2013-02-08 18:30:29
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/ratingText" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<RatingBar android:id="@+id/rating"
android:isIndicator="false"
android:stepSize="1.0"
android:numStars="5"
android:rating="0.0"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RatingBar>
</LinearLayout>活动
ratingText=(TextView)findViewById(R.id.ratingText);
rating=(RatingBar)findViewById(R.id.rating);
rating.setOnRatingBarChangeListener(this);
}
// implement abstract method onRatingChanged
public void onRatingChanged(RatingBar ratingBar,float rating, boolean fromUser){
ratingText.setText(""+this.rating.getRating());
}发布于 2013-02-08 18:26:49
ratingBar = (RatingBar) findViewById(R.id.ratingBar);
btnSubmit = (Button) findViewById(R.id.btnSubmit);
//if click on me, then display the current rating value.
btnSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MyAndroidAppActivity.this,
String.valueOf(ratingBar.getRating()),
Toast.LENGTH_SHORT).show();
}
});发布于 2013-02-08 18:31:51
使用以下代码
float num_of_rating = 0.0f;
RatingBar ratingbar_rb = (RatingBar)findViewById(R.id.ratingbar_rd);
新建(ratingbar_rb.setOnRatingBarChangeListener OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
num_of_rating = rating;
}});https://stackoverflow.com/questions/14770434
复制相似问题