java - 评级栏不可点击

标签 java android onclick touch ratingbar

我正在尝试在我的应用程序中添加一个评级栏,以便可以对问题对象进行评级。

这是我的评级栏的 XML 版本:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Question: "
            android:textSize="20sp"
            android:gravity="center"/>

        <EditText
            android:id="@+id/fragment_question_string"
            android:layout_width="0sp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:hint="New question"/>

    </LinearLayout>

    <RatingBar
        android:id="@+id/fragment_question_rating_bar"
        style="@style/Base.Widget.AppCompat.RatingBar.Small"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"/>

</LinearLayout>

这是我的代码部分,我在 fragment 的 onCreateView(LayoutInflater, View, Bundle) 方法中使用 RatingBar

RatingBar mRatingBar = (RatingBar) v.findViewById(R.id.fragment_question_rating_bar);
mRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            int r = (int) rating;

            try {
                mQuestion.rateQuestion(r);
            } catch (IllegalRatingValue illegalRatingValue) {
                illegalRatingValue.printStackTrace();
            }
        }
    });

问题是评级栏无法点击。当我尝试对问题进行评分时,它不会改变星星的数量。它看起来就像图像一样,因为它对触摸没有反应。我该如何解决这个问题?

最佳答案

我已使用这些步骤来进行用户评分。

在 XML 中

       <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize=".5"
        android:layout_gravity="center_vertical"
        android:progressTint="@color/grey"
        android:progressBackgroundTint="@color/grey"
        android:secondaryProgressTint="@color/grey"
        android:rating="0.0" />

在 Activity 中

RatingBar ratingBar=(RatingBar)findViewById(R.id. ratingBar);

float 评分 = ratingBar.getRating();

关于java - 评级栏不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36963827/

相关文章:

java - 运行此程序时出现无法访问的代码错误,但我不知道为什么

java - Spring 不使用默认语言环境中的源

java - 如何创建 "Open"和 "Closed"指标?

android - 从 Android AppWidget 播放/控制歌曲

jquery - 防止 anchor 内的默认单击按钮

java - AlertDialog 无法正常工作

javascript - 从 onclick 中排除子复选框

java - libGDX : get Label actor from stage by name

java - 在 mAuth.signInWithEmailAndPassword 方法中通过 Intent 更改 Activity

android - flutter 找到了多个文件,操作系统独立路径为 'AndroidManifest.xml'