User44 User44 - 1 month ago 6
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) {
@Override
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
number.setVisibility(View.GONE);
final TextView prompt = (TextView) findViewById(R.id.prompt);
prompt.setText(" Enter the number");
final EditText input = (EditText) findViewById(R.id.enterAnswer);
input.setOnKeyListener(new View.OnKeyListener() {
@Override
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();
input.setVisibility(View.GONE);
prompt.setVisibility(View.GONE);
if (answer.equals(loadG1)){
score[0]=+1;
}
return true;
default:
break;
}
}
return false;
}
});
}
}.start();


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

Answer

Looks like your EditText (R.id.enterAnswer) 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.

Comments