I think your code will flip the valve back and forth as long as the button is held down. Do you need to detect when the button first goes down, and only execute your logic then?
Untested code:
Code:
// run once
boolean status = false;
boolean buttonWasDown = false;
// run inside operator control loop, or teleopPeriodic, or whatever
boolean buttonIsDown = joystick.getRawButton(3);
if(buttonIsDown && !buttonWasDown)
{
if(!status)
{
solenoid.kforward();
status = true;
}
else
{
solenoid.kreverse();
status = false;
}
}
buttonWasDown = buttonIsDown;