Edittext does not accept Keylistener

Asked

Viewed 57 times

0

Eae guys, I’m trying to define a Reader for an Edittext but it’s giving error.

Error: setKeyListener (android.text.method.Keylistener) in Textview cannot be Applied to (com.example.calculaarea.Mainactivity)

My Code:

//Minha Main implementa a OnKeyListener e aqui passo ela ao EditText
this.mHolder.editLargura.setKeyListener(this);

//Essa é a implementaçao do método onKey
public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER)
        {
            return true;
        }
        return false;
    }

How could I correct this mistake?

1 answer

3


From the error it seems that the interface that Activity implements is not the one that the method setKeyListener() waiting.

I don’t know if you’re changing the method or if you’re switching the interface.

If you really want to use the method setKeyListener() so Activity has to build the interface Keylistener.

If, on the other hand, you want to use the interface Onkeylistener then the method to be used is setOnKeyListener()

  • Vlw man I hadn’t paid attention on On

Browser other questions tagged

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