97

My application have rating bars. I want to set the Rating bar is non-click able and no-touchable. For this i added the following code in xml file of each rating bar.

It is working in samsung galaxy Apollo GT-i5801. But it is not working in the HTC mobile. Why?

xml code

android:clickable="false"     
android:focusableInTouchMode="false"    
android:focusable="false"

thanks

Suraj Makhija
  • 1,368
  • 6
  • 16
naresh
  • 9,682
  • 25
  • 77
  • 123

4 Answers4

340

You could also set the RatingBar as indicator from the xml with the following:

android:isIndicator="true"
Andy
  • 6,419
  • 2
  • 25
  • 22
  • 4
    this is the best solution if you are using this in the list view. – AlbertRosa Jan 19 '12 at 22:04
  • It works but you cant change the ratings. i.e. android:rating="4" will not work. It will always be 5. – Vishal Jan 20 '20 at 13:36
  • @Vishal it may very well be the case; a lot of things change in 8 years. I'm not working on Android anymore, but from what I recall there was a way in which the rating could be set. Probably from code instead of XML. – Andy Jan 20 '20 at 13:51
  • @Andy - I do agree, I have just posted my comment for other developers reference. If one needs to disable the rating bar with rating indicator as 4, then it should be something like android:rating="4" and setOnTouchListener needs to be override for the indicator. – Vishal Jan 22 '20 at 12:55
20

This is it write this code in your setOnRatingBarChangeListener

ratingaddrate.setIsIndicator(true);

Update :

You can use this example in your XML

android:isIndicator="true"

also add this line to the Code

ratingBar.setFocusable(false);
alireza amini
  • 1,616
  • 1
  • 16
  • 33
19

Do not set enabled to false as this will dim the control. What you want to do is override the on touch listener like this:

import android.view.View.OnTouchListener;

RatingBar ratingBar = (RatingBar)findViewById(R.id.ratingBar);
ratingBar.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

So basically you intercept the touch and do nothing with it

Also add the following code too to block trackball rollovers

ratingBar.setFocusable(false);
Ryan C
  • 231
  • 3
  • 4
0

Add style="?android:attr/ratingBarStyleIndicator" into your layout
For example

<RatingBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/review_star"
        style="?android:attr/ratingBarStyleIndicator"
        android:scaleX=".5"
        android:rating="3.5"
        android:scaleY=".5"
        android:transformPivotX="0dp"
        android:transformPivotY="0dp"
        android:max="5"/>
Infomaster
  • 331
  • 3
  • 5