当我按下我的开关以使其显示“开”位置时,我实际上如何让它做一些事情,例如,将它链接到将播放器音量设置为 0 的方法?我猜它的接口FieldChangeListener
?
我所有的实现都发生在MainScreen
课堂上。
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);
我导入了一个名为 OpenGlSpriteDemo 的游戏演示,并查看了他们如何使用字段更改侦听器实现开始按钮,因此我尝试为 Labeledswitch 执行此操作。我是否朝着正确的方向前进?
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
}