How to Change Image of Rating Bar from Server

1k views Asked by At

I do have read how to make custom rating bar from here. But I want to make rating bar that retrieve image from the server.

Does it possible ? How ?

2

There are 2 answers

0
Nikhil On

it may be not the exact but definitely serve for your purpose with slight add on codes .

A sample rating bar using drawable

Here is the sample code

RatingBar mRatingBar = (RatingBar) findViewById(R.id.ratingbar);
mRatingBar.setStarEmptyDrawable(getResources().getDrawable(R.mipmap.star_empty));
mRatingBar.setStarHalfDrawable(getResources().getDrawable(R.mipmap.star_half));
mRatingBar.setStarFillDrawable(getResources().getDrawable(R.mipmap.star_full));
mRatingBar.setStarCount(5);
mRatingBar.setStar(2.5f);
mRatingBar.halfStar(true);
mRatingBar.setmClickable(true);
mRatingBar.setStarImageWidth(120f);
mRatingBar.setStarImageHeight(60f);
mRatingBar.setImagePadding(35);
mRatingBar.setOnRatingChangeListener(
        new RatingBar.OnRatingChangeListener() {
            @Override
            public void onRatingChange(float RatingCount) {
                Toast.makeText(MainActivity.this, "the fill star is" + RatingCount, Toast.LENGTH_SHORT).show();
            }
        }
);

You can use your own image from server in setStars . All you need to do is to convert your image from server into a drawable

Here is the gradle

  compile 'com.hedgehog.ratingbar:app:1.1.2'

For a detailed explanation and updated version use this github-link

Please give it a try and let me know your comments

0
TapanHP On

As you have referred the answer here, If that is your way then it's not possible cause you can not put a file in a Drawable folder at runtime, as R.java file is generated at compile time.