You could set two buttons up to to change the state of the solenoid when they transition from not being pressed -- to being pressed.
The only problem I foresee with this is if you ever wanted to stop the thing from moving, you would need to set up a new command on another button which set both solenoid channels to their false state. (Added to the code example)
This can be thought of as a rising edge trigger. Something (whatever is in the if statement) will happen once when the button is pressed, and never again until the button is released and pressed again.
Code:
//These should be declared outside of the method which code
// is executing in.
Boolean currentButton1Value = false,
prevButton1Value = false,
currentButton2Value = false,
prevButton2Value = false;
//The below code should be placed in whatever method is continually
// executing code (e.g. teleop periodic)
//Check the current button values
currentButton1Value = joystick1.getRawButton(1);
currentButton2Value = joystick1.getRawButton(2);
//If the button was just transitioned from not pressed to pressed,
// extend? completely.
if((currenButton1Value == true) && (prevButton1Value == false)) {
//The only way to get in here is if button 1 is currently true,
// and used to be false.
solenoid7.set(true);
solenoid8.set(false);
}
//If the button was just transitioned from not pressed to pressed,
// retract? completely.
//Using a simplified form for the boolean logic (does the same thing as above)
if(currenButton2Value && !prevButton2Value) {
solenoid7.set(false);
solenoid8.set(true);
}
//Keep a history of the button presses
prevButton1Value = currentButton1Value;
prevButton2Value = currentButton2Value;
if(joystick1.getRawButton(3)){
solenoid7.set(false);
solenoid8.set(false);
}
Note this code isn't tested, and I don't know what your application is, so I'm not sure if it fits the need well. Hope it helps.