I'm using a RatingBar and OnRatingBarChangeListener in my Code开发者_开发知识库.
The user can the rating once and after this I set
ratingBar.setEnabled(false)
.
I want to show the user advice that he can't rate anymore.
How can I achieve to set a Toast after the user touches the disabled RatingBar?
Anybody an idea?
greetings
You could set the rating to isIndicator after the user makes his first change You should prompt the user to make sure his change is exactly as he wished. It can get pretty difficult to rate when the property stepSize (how precise the rating is) is 0.5
//You could prompt the user using a dialog to confirm he is done rating
ratingBar.setIsIndicator(true);
That should leave the UI unchanged(no greyish blur) and prevent the user from making a change (just like setEnabled(false))
In XML Layout
android:isIndicator="true"
Hope it helped
As @Br0therzS0ul noted, it's isIndicator
.
Here's how in XMl:
android:isIndicator="true"
The moment you disable the rating bar, you could make an invisble overlay that will display a toast when it's clicked.
Set
ratingbar.setIsIndicator(true)
Now set the onClick Listener of rating bar or any parent view and display a toast if you receive a click
its very simple write in your onClick() method
if(ratingBar.getEnabled()){
Toast.makeText(<>,<YOUR message>,<>);
{
After applying either style="?android:attr/ratingBarStyleSmall" or scaleX/scaleY the click interaction with RatingBar is disabled. This works for me. Hope this helps you!
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:scaleX="0.8"
android:scaleY="0.8"
android:isIndicator="false"
android:numStars="5"
android:stepSize="0.5"/>
Just to add up, android:isIndicator="false" made the differece.
精彩评论