-2

I'm trying to bind the android's keyboard enter button as submit/go button, but it is showing that the onKeyDown method is not defined in this scope, below is attached the snapshot of my code

@Override
public boolean onKeyDown( int KeyCode, KeyEvent event)
{
    if (KeyCode == KeyEvent.KEYCODE_BACK)
        if (bro.cangoBack()) {
            bro.goBack();
            return true;
        }
}

Actually I'm trying to build a browser and I need the keyboard button as submit button.

CDspace
  • 2,639
  • 18
  • 30
  • 36
Satan
  • 3
  • 2
  • See this https://stackoverflow.com/questions/39517637/onkey-onkeydown-not-working – Ankita Sep 27 '17 at 07:05
  • You should not post your code or logs as an image, please refer to this https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557 – Chris Gomez Sep 28 '17 at 21:34

1 Answers1

0

onKeyDown it's a method that it's defined on the interface KeyEvent.Callback, that interface it's implemented in Activity, AppCompatActivity among others, you don't specify in which class you are trying to put your code, but given that it's not in an activity I will asume is in a fragment.

What you have to do, to solve this is move that code to your activity class, that would be the class that is either of these:

class SomeActivity extends AppCompatActivity {
}

class SomeActivity extends Activity {
}

class SomeActivity extends FragmentActivity {
}
Chris Gomez
  • 6,644
  • 4
  • 18
  • 39