我有一个搜索栏,我想在按下按钮时消失,并在倒计时后重新出现。我在倒计时后的 onFinish()
方法中使用了 seekBarTimeToPlay.setVisibility(view.INVISIBLE);
。
但是,我收到错误“无法解析符号“ View ””。并且“无法解析符号‘seekBarTimeToPlay’。”但似乎通过在方法内添加另一个 SeekBareekBarTimeToPlay = (SeekBar) findViewById(R.id.seekBarTimeToPlay);
来解决此问题。
//change timeToPlay seekBar
SeekBar seekBarTimeToPlay = (SeekBar) findViewById(R.id.seekBarTimeToPlay);
//set progress/thumb pos to right place
seekBarTimeToPlay.setProgress(timeToPlay);
seekBarTimeToPlay.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
timeToPlay = progress;
updateTimeToPlay(timeToPlay, false);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
updateTimeToPlay(timeToPlay, true);
}
});
//start playing, countdown
final Button buttonMain = (Button) findViewById(R.id.buttonMain);
buttonMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//countdown, updating time to tidy text view, progress bar or clock animation
SeekBar seekBarTimeToPlay = (SeekBar) findViewById(R.id.seekBarTimeToPlay);
if (phase == "none") { //parent presses button, child starts playing
phase = "playing";
buttonMainText = "Pack Away Now";
//hide seekBar, doesn't change layout
seekBarTimeToPlay.setVisibility(View.INVISIBLE);
startCountDown(timeToPlay);
} else if (phase == "playing") {//parent presses button to pack away before time ended
phase = "tidying";
buttonMainText = "Confirm tidied up";
countDownTimer.cancel(); //maybe error if countdown isn't running, if statement might solve
updateTimeToPlay(timeToTidy, false);
startCountDown(timeToTidy); //new 10 minute countdown to wait for conformation that toys are away
//waiting to receive conformation, if received cancel countdown n that
} else if (phase == "tidying") { //parent presses button confirming packed away
countDownTimer.cancel(); //maybe error if countdown isn't running, if statement might solve
phaseWasTidying();
}
buttonMain.setText(buttonMainText); //change text to whatever stage
//returns here after button pressed
seekBarTimeToPlay.setVisibility(View.VISIBLE); //make visible again
}
});
}
如何通过其他方法更改可见性?我也无法使用我不明白的 static
。
最佳答案
View 应该从大写开始,因为它是类名:
seekBarTimeToPlay.setVisibility(View.GONE);
或
seekBarTimeToPlay.setVisibility(View.VISIBLE);
<小时/>
并记住导入:
导入 android.view.View;
关于java - 如何从 OnCreate 方法外部更改小部件的可见性? Java Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55083318/