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

  • SEARCH
  • Home
  • 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 8605823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:55:59+00:00 2026-06-12T02:55:59+00:00

I am using a RatingBar element in my app, and im trying to set

  • 0

I am using a RatingBar element in my app, and im trying to set it up with an OnRatingChangedListener. In the listener, im doing different stuff using if statements on a variable. Problem is, for some reason when i have multiple options this listener isn’t working. It is setup in the onCreate() method, before the variable in the if statements is getting a value, but i tried to move it to a different location with no success at all.

My onCreate():

bar = (RatingBar) findViewById(R.id.serviceLevel);
    bar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                boolean fromUser) {

        if(Code==null){
            Toast.makeText(TipCalculatorActivity.this, "Locationing error occured, please report to the developer.", Toast.LENGTH_LONG).show();
        }else if(Code=="1"){
            if(rating==0){
                autochange.setText("Precentage: 0%");
                precentage = 0;
                calculate(value, precentage);
            }else if(rating==0.5){
                autochange.setText("Precentage: 10%");
                precentage = 8;
                calculate(value, precentage);
            }else if(rating==1){
                autochange.setText("Precentage: 11%");
                precentage = 9;
                calculate(value, precentage);
            }else if(rating==1.5){
                autochange.setText("Precentage: 11%");
                precentage = 10;
                calculate(value, precentage);
            }else if(rating==2){
                autochange.setText("Precentage: 12%");
                precentage = 11;
                calculate(value, precentage);
            }else if(rating==2.5){
                autochange.setText("Precentage: 12%");
                precentage = 12;
                calculate(value, precentage);
            }else if(rating==3){
                autochange.setText("Precentage: 13%");
                precentage = 13;
                calculate(value, precentage);
            }else if(rating==3.5){
                autochange.setText("Precentage: 13%");
                precentage = 14;
                calculate(value, precentage);
            }else if(rating==4){
                autochange.setText("Precentage: 14%");
                precentage = 15;
                calculate(value, precentage);
            }else if(rating==4.5){
                autochange.setText("Precentage: 14%");
                precentage = 16;
                calculate(value, precentage);
            }else if(rating==5){
                autochange.setText("Precentage: 15%");
                precentage = 17;
                calculate(value, precentage);
            }
        }else if(Code=="2"){
            if(rating==0){
                autochange.setText("Precentage: 0%");
                precentage = 0;
                calculate(value, precentage);
            }else if(rating==0.5){
                autochange.setText("Precentage: 10%");
                precentage = 10;
                calculate(value, precentage);
            }else if(rating==1){
                autochange.setText("Precentage: 11%");
                precentage = 11;
                calculate(value, precentage);
            }else if(rating==1.5){
                autochange.setText("Precentage: 12%");
                precentage = 12;
                calculate(value, precentage);
            }else if(rating==2){
                autochange.setText("Precentage: 13%");
                precentage = 13;
                calculate(value, precentage);
            }else if(rating==2.5){
                autochange.setText("Precentage: 14%");
                precentage = 14;
                calculate(value, precentage);
            }else if(rating==3){
                autochange.setText("Precentage: 15%");
                precentage = 15;
                calculate(value, precentage);
            }else if(rating==3.5){
                autochange.setText("Precentage: 16%");
                precentage = 16;
                calculate(value, precentage);
            }else if(rating==4){
                autochange.setText("Precentage: 17%");
                precentage = 17;
                calculate(value, precentage);
            }else if(rating==4.5){
                autochange.setText("Precentage: 18%");
                precentage = 18;
                calculate(value, precentage);
            }else if(rating==5){
                autochange.setText("Precentage: 19%");
                precentage = 19;
                calculate(value, precentage);
            }
        }
    }
});

My Code variable is set after an AsyncTask is done, so probably after the UI is generated. Any solution?

  • 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-12T02:56:00+00:00Added an answer on June 12, 2026 at 2:56 am

    In order to make your code work you’ll have to use the equals() method to check if Code has the right value:

    // ...
    } else if (Code.equals("1")){
    // ...
    

    == will test the references and will return false as the two references don’t point to the same object.

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

Sidebar

Related Questions

Using InteliJ IDEA , I am trying to set up multiple projects to run
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using jQuery I'm trying to obtain the rotation state of an object but in
I'm using a ratingbar with a custom style that is acting as an indicator,
Using mercurial, I've run into an odd problem where a line from one committer
I'm using the ajaxtoolkit:Rating. It all works fine except I'm trying to write a
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True)
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Rails 3.2.0 with haml, sass and coffeescript: Basically I am trying to disable

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.