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
}

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:
and