Tecnologia do Blogger.
RSS

[androidbrasil-dev] Implementar OnTouchListener()

Olá.
Tenho uma activity (MainActivity) que contém um background e uma imageview, ela está vinculada uma main.xml.
Quero mudar a cor da imageview ao pressiona-la, estou tentando implementar usando o OnTouchListener, porem quando coloco o codigo abaixo trava. 
Sem ele carrega normal, quando coloco ele trava. 
Ele está dentro do método Oncreate e dá um erro:
Multiple markers at this line
- implements android.view.View.OnTouchListener.onTouch
- The method onTouch(View, MotionEvent) of type new View.OnTouchListener(){} must override a superclass 
method

Se eu retiro o @Override o erro desaparece, mas como falei trava ao carregar a view. Alguma dica ?

Obrigado.


ImageView connect = (ImageView) findViewById(R.drawable.connect);
connect.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    ImageView view = (ImageView) v;
                    
                    view.getDrawable().setColorFilter(0x77000000,Mode.MULTIPLY);
                    view.invalidate();
                    break;
                }
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL: {
                    ImageView view = (ImageView) v;
                    
                    view.getDrawable().clearColorFilter();
                    view.invalidate();
                    break;
                }
            }

            return true;
        }
    });

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário