[英]Android Ratingbar has no response
I am making a Ratingbar to allow user to rate for something. 我正在制作一个Ratingbar,以允许用户对某些内容进行评分。 Thus,I use this java code 因此,我使用此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)}
});
and this xml code 和这个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" />
but the Ratingbar does not change when I press on it. 但是当我按下它时,等级栏不会改变。 I have done many searching in vain,please help me to solve the problem. 我白费了很多功夫,请帮助我解决问题。
Try modify to this 尝试对此进行修改
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();
}
});
You can do like this. 你可以这样
<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" />
Just setting android:isIndicator="false"
in the RatingBar
只需在RatingBar
设置android:isIndicator="false"
Then use in the Activity . 然后在Activity中使用。
rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
@Override
public void onRatingChanged(RatingBar ratingBar,float rating,boolean fromUser){
value.setText("Rated:"+rating)}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.