User44 User44 - 4 months ago 18
Android Question

How to control appearance of EditText box?

I intend to have an EditText box where a user can input data appear after a timer ends. To do this, I placed in in the onFinish section of my timer. This didn't work, because as soon as I access the screenview, the EditText box appears before the timer even starts (timer starts when a button is pressed). The box does go away when a user inputs their data and presses enter, as expected, but it appears before the timer even starts, which I do not want.

new CountDownTimer(4000, 1000) {
public void onTick(long millisUntilFinished) {
public void onFinish() {
final TextView prompt = (TextView) findViewById(;
prompt.setText(" Enter the number");
final EditText input = (EditText) findViewById(;
input.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode){
case KeyEvent.KEYCODE_ENTER:
Editable answer = input.getText();
if (answer.equals(loadG1)){
return true;
return false;

This is the only part of my program where the EditText box appears, thanks in advance for any help.


Looks like your EditText ( is being defined on an XML layout. So, you will need to set the default visibility to false. Then turn it to true when the timer is finished.