onKeyDown when the Spinner is open

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 you be detecting that the spinner was closed?

Thank you

    
asked by anonymous 03.11.2016 / 19:48

2 answers

1

The KEY event does not work because it will be triggered in the active Spinner activity. Here's an example of how to fix it.

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;
            }
        });
    
03.11.2016 / 19:55
0

What if you use onBackPressed ?

@Override
public void onBackPressed() {
   //aqui você controla o voltar fisico do aparelho
}
    
03.11.2016 / 19:52