سؤال

I'm new to android development
I need to create a RatingBar that shows rating according to Application details .
My App calculate a value according to user input and it will be shown in RatingBar .
That bar only shows the value (eg. 4/5 stars ) according to the calculated value
I need to create it that users can't change RatingBar's value directly .They only enter the input and that input calculate some value and that value need to be displayed in RatingBar.

Can you please help me to do this? This is the only way than I can think of using RatingBar (according to my knowledge).

هل كانت مفيدة؟

المحلول

Try this out.I think this will solve your problem

This is java code

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

XML code

<RatingBar

         android:id="@+id/ratingBar1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" 
         android:numStars="5"
         android:progress="30"
         android:clickable="false"     
         android:focusableInTouchMode="false"    
         android:focusable="false"

        />

نصائح أخرى

If You Need to restrict the user to manually alter the rating bar you need to apply onTouchListener on rating bar instance and return true

Try isIndicator attribute. If you set true, users won't be able to change the value by touching the RatingBar.

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:isIndicator="true" />
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top