Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:24:11+00:00 2026-06-04T05:24:11+00:00

I find myself a little baffled here. I’m fairly new to android/java development so

  • 0

I find myself a little baffled here. I’m fairly new to android/java development so please help out here to identify what I’m doing wrong. I have checked aggressively throughout google, android dev and stack but couldn’t find much info on this.

I have a string variable with a number as theRating. e.g. 2.5 (out of 10)
I am trying to display this using ratingbarstylesmall… It’s for showing only and not rating.

RatingBar rb = new RatingBar(this, null, android.R.attr.ratingBarStyleSmall);
rb.setIsIndicator(true);
rb.setNumStars(5);
rb.setStepSize((float) 0.5);
rb.setMax(10);
rb.setRating(Integer.parseInt(theRating));
llTextEtc.addView(rb);

The stars load fine inside LienarLayout (llTextEtc), show up in the right place, it’s the right style stars that i want (small) but…

it’s completely random. Some show 8 stars, some show 15 then back to 7 and so on. Totally random. What am I doing wrong?

Thanks guys

Update:
With help from the accepted answer:
A LinearLayout was added to hold the ratingbar with wrap_content layout. Otherwise the parent (scrollview) became wrap_content.

LinearLayout llRating = new LinearLayout(this);
RatingBar rb = new RatingBar(this, null, android.R.attr.ratingBarStyleSmall);
  rb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  rb.setIsIndicator(true);
  rb.setNumStars(5);
  rb.setRating(Float.parseFloat(theRating)/2);
llRating.addView(rb);
llTextEtc.addView(llRating);

setStepSize and setMax was also removed, Rating was set to float instead of integer. The stars are calculated and then set. stepSize and Max doesn’t help when isIndicator is true.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:24:12+00:00Added an answer on June 4, 2026 at 5:24 am

    I noticed a couple of problems here. First and most important you need to set the layout width to WRAP_CONTENT for it to work properly. The following is from the dev guide:

    The number of stars set (via setNumStars(int) or in an XML layout) will be shown when the layout width is set to wrap content (if another layout width is set, the results may be unpredictable).

    Secondly I noticed that you have set the stepSize to a float and you are seting the rating using an Interger. I would first convert the value from the URL feed to a Float and then validate it before passing it to the rating bar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I find myself with a need for a java utility for taking a fully-qualified
I often find myself designing simple little web projects that are serving up aggregate
On a regular basis I find myself writing little utility programs that use some
I find myself needing to learn a little bit of JSP for my Software
I often find myself wanting to change just something little in a colorscheme, but
I'm using Java 6. Sometimes I find myself doing something like this. Map<String,List<Integer>> myMap;
I've been working on a little project, and I find myself in a position
I often find myself wanting to open Xcode and do a little coding on
Here is the scenario I find myself in. I have a reasonably big table
I hope you can help me with my little problem here. I'm just starting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.