我好像在处理ratingbar点击时遇到了问题。评分条显示得很好,也有默认值,但问题是我无法更改任何值或启用它。我尝试了许多不同的方法(例如在布局中启用,在Java中完全构建等),但它们似乎都没有影响。这是我最新版本的评分条。我一定做错了什么以致于无法捕获点击。
Java代码:
RatingBar showRatingBar = (RatingBar) findViewById(R.id.showRatingBar);
showRatingBar.setEnabled(true);
showRatingBar.setClickable(true);
showRatingBar.setRating(0);
showRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
System.out.println("showRating.buildRatingBar: " +rating);
ratingBar.setRating(rating);
}});
showRatingBar.refreshDrawableState();
布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/showQualityLabel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/show_rating_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#E6E6E6"
android:textSize="12sp" />
<RatingBar
android:id="@+id/showRatingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="5"
android:numStars="5"
android:rating="0"
android:stepSize="1"/>
</LinearLayout>
提前感谢您。
Craig