首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android Ratingbar无响应

Android Ratingbar无响应
EN

Stack Overflow用户
提问于 2017-07-27 09:53:25
回答 2查看 73关注 0票数 0

我正在制作一个Ratingbar,允许用户对某些东西进行评分。因此,我使用下面的java代码

代码语言:javascript
复制
    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代码

代码语言:javascript
复制
<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时,它不会改变。我已经搜索了很多次都没有结果,请帮我解决这个问题。

EN

回答 2

Stack Overflow用户

发布于 2017-07-27 10:03:31

尝试对此进行修改

代码语言:javascript
复制
 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();
        }
  });
票数 0
EN

Stack Overflow用户

发布于 2017-07-27 10:17:35

你可以这样做。

代码语言:javascript
复制
<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"

然后在活动中使用。

代码语言:javascript
复制
rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
    @Override
    public void onRatingChanged(RatingBar ratingBar,float rating,boolean fromUser){
        value.setText("Rated:"+rating)}
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45340042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档