onKeyDown when Spinner is open

Asked

Viewed 41 times

0

Hello I’m trying to do an action when a user closes the spinner using the back button of the device.

But the "onKeyDown" event does not run when the spinner is open, only if it is closed.

How could it be detecting that the spinner was closed?

Thank you

2 answers

1

The KEY event does not work because it will be fired in the "Spinner" Activity that is active. Below is an example of how to solve.

Spinner oi = (Spinner) findViewById(R.id.meuspinner);
oi.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                //Faço a tratativa aqui.
                return true;
            }
        });

0

And if you use the onBackPressed?

@Override
public void onBackPressed() {
   //aqui você controla o voltar fisico do aparelho
}
  • It doesn’t work. I already figured out the reason and the fix I’ll be posting here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.