android: onClickListener for relativelayout

Viewed 9429

I have a relativelayout and have coded the onTouchListener to highlight background as follows:

    relative3.setOnTouchListener(new OnTouchListener() 
    {
        @Override
        public boolean onTouch(View arg0, MotionEvent event) 
        {
            if(event.getAction()==MotionEvent.ACTION_DOWN )
            {
                relative3.setBackgroundColor(getResources().getColor(R.color.tran_grey));
            }

            if((event.getAction()==MotionEvent.ACTION_UP || event.getAction()==MotionEvent.ACTION_CANCEL))
            {
                relative3.setBackgroundColor(getResources().getColor(android.R.color.transparent));
            }
            return true;
        }           
    }); 

and to perform an action upon onClick

    relative3.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
            custom_toast("Redirecting...");
        }
    }); 

Question:

The relativelayout could show highlight upon ACTION_DOWN and turn back to transparent upon ACTION_UP. Yet it is clicked, the toast simply does not appear as coded.

How could that be modified? Thanks!

3 Answers
Related