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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:22:50+00:00 2026-06-12T01:22:50+00:00

When I press my switch so that it shows the on position, how do

  • 0

When I press my switch so that it shows the “on” position, how do I actually make it do something, for example, link it to a method that sets the volume of a player to 0? I’m guessing its Interface FieldChangeListener?

All my implementation occurs in the MainScreen class.

Bitmap switch_left = Bitmap.getBitmapResource("switch_left.png");
Bitmap switch_right = Bitmap.getBitmapResource("switch_right.png");
Bitmap switch_left_focus = Bitmap.getBitmapResource("switch_left_focus.png");
Bitmap switch_right_focus = Bitmap.getBitmapResource("switch_right_focus.png");

LabeledSwitch silentSwitch = new LabeledSwitch(switch_left, switch_right, switch_left_focus, switch_right_focus, "on", "off", true );
JustifiedHorizontalFieldManager silent = new JustifiedHorizontalFieldManager( new LabelField( "Silent Mode" ), silentSwitch, false, USE_ALL_WIDTH );
silent.setPadding(5,5,5,5);
add(silent);

I imported a game demo called OpenGlSpriteDemo, and looked at how they implemetned the start button with field change listener, so I tried to do that for the Labeledswitch. Am I heading in the right direction?

LabeledSwitch silentSwitch = new LabeledSwitch(switch_left, switch_right, switch_left_focus, switch_right_focus, "on", "off", false );
silentSwitch.setChangeListener(this);

public void fieldChanged(Field arg0, int arg1) 
{
    //If user sets the switch to on, reduce the volume to 0, 
    // else if user sets the switch to false, change it back 
    // to the default volume    
}

enter image description here

  • 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-12T01:22:51+00:00Added an answer on June 12, 2026 at 1:22 am

    Figured it out using a boolean flag to tell if its silent already or not, and used a get and set methods of the volume variable and pass it to:

    volume.setLevel(getVolume());       
    

    and

    boolean isSilent = false;
    
    public void fieldChanged(Field field, int context) 
    {
        if(!isSilent && field == silentSwitch)
        {
            setVolume(0);
            isSilent = true;
        }
        else if(field == silentSwitch && isSilent)
        {
            setVolume(20);
            isSilent = false;           
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi im creating a app that generates random text when i press a button
I have a webpage that shows a list of results. I click on one
I have a function in jQuery that does something like the following to allow
I'm having a problem displaying an AlertDialog from within the onOptionsItemSelected method. That is,
Is it possible to the show the previous statement in the method that I'm
I want that when I press login button I get the response back in
When calling switch-to-buffer , in the minibuffer, when you press SPACE , you can
Hi basically I am trying to switch to a popup window then press a
when im pressing spacebar, chrome shows error: Uncaught TypeError: Object # has no method
I have the following function that is used as the glutKeyboardFunc function parameter: void

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.