3

I have a CustomAutoCompleteTextView and I want to be able to call showDropDown(); when the user double-tap on it.

As the title says implements GestureDetector.OnDoubleTapListener sounds like a good solution, but once added the mandatory methods to my custom view I have no idea on how to set the whole thing up

These are the methods to implement:

 @Override public boolean onSingleTapConfirmed(MotionEvent e) { return false; } @Override public boolean onDoubleTap(MotionEvent e) { return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } 

I want to archive something like this:

@Override public boolean onDoubleTapEvent(MotionEvent e) { showDropDown();//AutoCompleteTextView's this line is enough but the event is never triggered return super.doYourThing(); } 

3 Answers 3

4

I've found a better way than implements GestureDetector.OnDoubleTapListener to archive this, notice that this solution is for implement double tap inside a custom view and all of its instances

boolean firstTouch = false; long time; @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == event.ACTION_DOWN){ if(firstTouch && (System.currentTimeMillis() - time) <= 300) { firstTouch = false; showDropDown();//In my case I want to showDropDown() change this line for whatever you want to do } else { firstTouch = true; time = System.currentTimeMillis(); return super.onTouchEvent(event); //return false;Use this if you dont want to call default onTouchEvent() } } return super.onTouchEvent(event); //return false;Use this if you dont want to call default onTouchEvent() } 
Sign up to request clarification or add additional context in comments.

Comments

3

1) create a new GestureDetector()

detector = new GestureDetector(this,new OnGestureListener() { @Override public boolean onDoubleTap(MotionEvent e) { showDropDown() return true; } 

2) Append your CustomAutoCompleteTextView with a OnTouchListener

txt.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); 

3 Comments

Like this still not triggering
I guess yes but I can just guess since you are not sharing a code snipped which shows where and how you add/create your TextView
I'm sure this will work but it has a problem for me, sorry for not specifying, i have several CustomAutoCompleteTextView and i want all of them to do the same so this way will be a lot of work. What I wan is implement the double tap function in the custom class that extends AutoCompleteTextView. And i just found a way! Sharing in a min. PD:Ty for your time mate!
0

This is what worked well for me:

tapDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener());

tapDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e){ //Notified when a single-tap occurs. Log.w("Debug","Single tap event occurred in view with ID: "+ getId()); return true; } @Override public boolean onDoubleTap(MotionEvent e) { Log.w("Debug","Double tap event occurred in view with ID: "+ getId()); return true; } @Override public boolean onDoubleTapEvent(MotionEvent e) { //Notified when an event within a double-tap gesture occurs, including the down, move, and up events. return true; } }); 

As mentioned in the previous solution:

txt.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { tapDetector.onTouchEvent(event); return false; } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.