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 7497065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:55:01+00:00 2026-05-29T18:55:01+00:00

I’m using a ratingbar with a custom style that is acting as an indicator,

  • 0

I’m using a ratingbar with a custom style that is acting as an indicator, however I want users to still be able to click the ratingbar to bring up a custom dialog with a ratingbar that can be changed.

Is there anyway to do this without using images?

To illustrate:

RatingBar Highlighed

  • 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-05-29T18:55:02+00:00Added an answer on May 29, 2026 at 6:55 pm

    For those who are having the same issues down the road, I figured it out.

    ratingBar = (RatingBar) findViewById(R.id.rbMyRating);
    ratingBar.setIsIndicator(true);
    ratingBar.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                myRatingDialog.show();
                v.setPressed(false);
            }
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                v.setPressed(true);
            }
            if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                v.setPressed(false);
            }
            return true;
        }
    });
    

    The key was that you can still use setPressed to true, even though isIndicator is true. This will allow only allow the RatingBar to highlight but not change.

    You can manage the setPressed state using the OnTouchListener. ACTION_UP and ACTION_DOWN control touch events on the widget, ACTION_CANCEL handles any event outside of the widget.


    The problem with the above code is it does not support key events. To do this the following additional code is needed:

    Float rating = 4f;
    ratingBar.setFocusable(true);
    ratingBar.setTag(rating);
    ratingBar.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
                    v.setPressed(false);
                    myRatingDialog.show();  
                } else if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
                    if (v.focusSearch(View.FOCUS_LEFT) != null)  v.focusSearch(View.FOCUS_LEFT).requestFocus();
                } else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
                    if (v.focusSearch(View.FOCUS_RIGHT) != null) v.focusSearch(View.FOCUS_RIGHT).requestFocus();
                }
            }
            return false;
        }
    });
    ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            ratingBar.setRating((Float) ratingBar.getTag());
        }
    });
    

    The above code uses both the OnKeyListener and setOnRatingBarChangeListener. To enable key events you will need to set setFocusable(true). You will also need to manually wire up the key events for KEYCODE_ENTER and KEYCODE_DPAD_CENTER.

    A problem with setFocusable = true is that you are now able to change the RatingBar rating using the KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT. To solve this you use onRatingBarChangeListener to reset the RatingBar’s rating. You can store the rating in the RatingBar’s tag. REMEMBER, you will need to change the tag value when you change the rating through the dialog.

    As a result of using onRatingBarChangeListener you will now be faced with one final issue. Since you are automatically changing the rating, the user will not be able to focus other UI elements with KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT. To solve this you simply use the OnKeyListener to detect left and right DPad actions and change the focus using searchFocus and requestFocus. Just remember that searchFocus returns null if no UI element is found.

    Hope this helps anyone else who runs into this problem. 🙂

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.