我正在制作一个Ratingbar,允许用户对某些东西进行评分。因此,我使用下面的java代码
setContentView(R.layout.restaurant_detail);
value=(TextView) findViewById(R.id.textView23) ;
rb=(RatingBar) findViewById(R.id.ratingBar);
rb.setOnRatingBarChangeListener(new
RatingBar.OnRatingBarChangeListener(){
@Override
public void onRatingChanged(RatingBar ratingBar,float rating,boolean fromUser){
value.setText("Rated:"+rating)}
});这段xml代码
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:numStars="5"
android:rating="4.5"
android:stepSize="0.5" />
<TextView
android:id="@+id/textView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />但当我按下Ratingbar时,它不会改变。我已经搜索了很多次都没有结果,请帮我解决这个问题。
发布于 2017-07-27 10:03:31
尝试对此进行修改
rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(getApplicationContext(),"Your Selected Ratings : " + String.valueOf(rating),Toast.LENGTH_LONG).show();
}
});发布于 2017-07-27 10:17:35
你可以这样做。
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"
android:numStars="5"
android:rating="4.5"
android:stepSize="0.5" />
<TextView
android:id="@+id/textView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />只需在RatingBar中设置android:isIndicator="false"
然后在活动中使用。
rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
@Override
public void onRatingChanged(RatingBar ratingBar,float rating,boolean fromUser){
value.setText("Rated:"+rating)}
});https://stackoverflow.com/questions/45340042
复制相似问题