Skip to content Skip to sidebar Skip to footer

Can We Give Both Ontouchlistener Event And Onclicklistener On A Single Text View?

Can we give both onTouchListener event and onClickListener on a single text view...if yes can I have sample code for it.. Thanks Ali Yes thank you friends..it works!!! But there i

Solution 1:

Here you are:

TextView tv = (TextView) getActivity().findViewById(R.id.textview_example);
                tv.setOnClickListener( newOnClickListener() {

                    @OverridepublicvoidonClick(View v) {
                        // TODO Auto-generated method stub//YOUR CODE HERE
                    }
                });

                tv.setOnTouchListener( newOnTouchListener() {

                    @OverridepublicbooleanonTouch(View v, MotionEvent event) {
                        // TODO Auto-generated method stub//YOUR CODE HEREreturnfalse;
                    }
                } );

You have to remember that maybe a TouchEvent will be also fired when you receive a ClickEvent.

UPDATE:

I think that everything will be much more clear if you take a look at the Input Events documentation.

Solution 2:

In addition to the above answer, i would like to add that onTouchlistener will be activated onKeyDown() initially and will keep on firing whenever view is touched

and onClickListener will be fired onKeyUp()

Post a Comment for "Can We Give Both Ontouchlistener Event And Onclicklistener On A Single Text View?"