Questions tagged [ontouchlistener]

Android interface to define a callback to be invoked when a view is touched.

ontouchlistener
Filter by
Sorted by
Tagged with
228 votes
9 answers
137k views

HorizontalScrollView within ScrollView Touch Handling

I have a ScrollView that surrounds my entire layout so that the entire screen is scrollable. The first element I have in this ScrollView is a HorizontalScrollView block that has features that can be ...
Joel's user avatar
  • 6,203
187 votes
6 answers
129k views

Android button has setOnTouchListener called on it but does not override performClick

When I try to add onTouchListner() to a button, it gets me the Button has setOnTouchListener called on it but does not override performClick warning. Does anyone know how to fix it? ...
Garry's user avatar
  • 2,295
170 votes
9 answers
89k views

onTouchListener warning: onTouch should call View#performClick when a click is detected

I have created a onTouchListener. Unfortunately onTouch() method throws me a warning: com/calculator/activitys/Calculator$1#onTouch should call View#performClick when a click is detected What does ...
Trzy Gracje's user avatar
  • 3,029
68 votes
12 answers
48k views

Android - Hold Button to Repeat Action

I'll admit straight off that I'm new to development and trying my hand at Android. I've been trying to search the 'net to find advice on how to implement some "Hold Button to Repeat Action" -...
Mark's user avatar
  • 797
65 votes
9 answers
32k views

EditText in Listview loses focus when pressed on Android 4.x

I know there are a lot of similar questions out here but I couldn't get any of the provided solutions working in a simple sample app. The problem occurs when the softkeyboard is shown for the first ...
Display name's user avatar
  • 2,707
64 votes
7 answers
60k views

onTouchevent() vs onTouch()

After many experiments with onTouchEvent and onTouch, I found that onTouch works everywhere you want (whether it is in activity or view) as long as you have declared the interface and put the Listener ...
stelios's user avatar
  • 1,027
61 votes
2 answers
90k views

How to handle Touch Events on a Fragment?

I'm building an interface where I need to process touch events. In particular I would to be able to enable them only to a confined area in a fragment. To better understand the problem, to respect the ...
user3319400's user avatar
58 votes
6 answers
14k views

Using BottomSheetBehavior with a inner CoordinatorLayout

The design support library v. 23.2 introduced BottomSheetBehavior, which allows childs of a coordinator to act as bottom sheets (views draggable from the bottom of the screen). What I’d like to do is ...
natario's user avatar
  • 25.1k
47 votes
13 answers
46k views

Can't handle both click and touch events simultaneously

I am trying to handle touch events and click events on a button. I do the following: button.setOnClickListener(clickListener); button.setOnTouchListener(touchListener); When any one listener is ...
Ragunath Jawahar's user avatar
39 votes
7 answers
91k views

Kotlin OnTouchListener called but it does not override performClick

How to override performClick in Kotlin to avoid warning? next.setOnTouchListener(View.OnTouchListener { view, motionEvent -> when (motionEvent.action){ MotionEvent.ACTION_DOWN -...
lambda's user avatar
  • 990
34 votes
4 answers
26k views

ViewPager intercepts all x-axis onTouch events. How to disable?

Scope There is a viewpager of two fragments. One of those fragments has a layout witch listens to onTouch changes at X-axis. Problem Layout doesn't get almost all Action.Move events when touching and ...
Oleksii Malovanyi's user avatar
33 votes
7 answers
29k views

OnTouchEvent not working on child views

I have a Linear Layout that has a Button and a TextView on it. I have written a OnTouchEvent for the activity. The code works fine if I touch on the screen, but if I touch the button the code does not ...
user1438128's user avatar
31 votes
5 answers
20k views

Handling Intercept touch event without extending ViewGroup

I have a one RelativeLayout and this layout is having nearly 10 views in it. I have set OnTouchListener to this Layout and doing some work in it and returning true. this listener is working fine ...
RuntimeException's user avatar
29 votes
5 answers
62k views

Android: OnTouch, MotionEvent.ACTION_MOVE is not recognized?

Here is my code, I want to detect when my finger goes down the screen so when I touch the screen I detect the ACTION_DOWN but when I go down the screen with my finger, ACTION_MOVE is not recognized, ...
morg's user avatar
  • 1,175
27 votes
3 answers
21k views

Playing default android sound of button, clicking onTouch() method

In my android app I have some buttons, that should work with onTouch() method, course I need to change button's text, when finger in ACTION_DOWN position. But this buttons should to play default ...
diamondhands003's user avatar
26 votes
6 answers
28k views

How to combine OnClickListener and OnTouchListener for an ImageButton

I need to do something when the user clicks the ImageButton I've tried to create a static class that implements both OnClickListener and OnTouchListener static class ClickListenerForScrolling ...
Tobias Moe Thorstensen's user avatar
26 votes
6 answers
12k views

End up activity on swipe right?

I have to finish Activity when user offer a right swipe anywhere in the screen. I have tried with GestureDetector and that is works fine if there is neither ScrollView nor RescyclerView exists in the ...
Stella's user avatar
  • 1,817
23 votes
7 answers
26k views

Detect touch event on a view when dragged over from other view

How do I detect the touch event if the user touches on view A and drags to bottom over the view B. I want to detect the touch event in View B. I added touch listener in view B but doesn't receive ...
dcanh121's user avatar
  • 4,685
23 votes
1 answer
25k views

Swipe and OnClick events in RecyclerView

I'm trying to implement a swipe to dismiss action in a RecyclerView but when I set an OnClickListener on any View in a ViewHolder it overrides all OnTouch events on that view. I can abandon ...
Ivan Fork's user avatar
  • 822
21 votes
8 answers
23k views

OnTouch works, but OnClickListener doesn't?

I created a widget/control that I can reuse which I created by extending RelativeLayout. Then, in one of my Activities, I created a bunch of these widgets in a loop. However, I ran into an issue when ...
tpow's user avatar
  • 7,699
21 votes
5 answers
29k views

"Press and hold" button on Android needs to change states (custom XML selector) using onTouchListener

I've got a button graphic which needs to have "press and hold" functionality, so instead of using onClickListener, I'm using onTouchListener so that the app can react to MotionEvent.ACTION_DOWN, ...
Octoth0rpe's user avatar
  • 2,267
21 votes
1 answer
55k views

Image in Canvas with touch events

Seems simple, and yet I'm having problems with implementation. I want a canvas with image on screen including onTouch events. I have tried ImageView but I was not able to use canvas. I have tried ...
no9's user avatar
  • 6,484
19 votes
7 answers
27k views

singletap touch detect in Ontouch method of the view

I needed a singletap touch detect in my custom view's ontouch method. I tried getting the x and y values in both ACTION-DOWN and ACTION-UP and in ACTION-UP I gave a condition that if a the values of X ...
Sandeep R's user avatar
  • 2,294
19 votes
2 answers
8k views

Android: Pass gesture event to another view

I am continuing work on my Sticky ListView, in which a specified view in a ListView will stick to the top and/or bottom as it passes by. I've accomplished this by setting up a View that is identical ...
Josh's user avatar
  • 2,685
19 votes
0 answers
4k views

Android: How to intercept touch event in ViewPager2

How to prevent swiping in androidx ViewPager2 when the touch event is coming from inside a nested view (e.g. a HorizontalScrollView, etc)? I expected this to be possible by overriding ViewPager2....
ccpizza's user avatar
  • 30.3k
18 votes
7 answers
45k views

Android : ImageView getID(); returning integer

I've set up an onTouch class to determine when one of my 40 buttons is pressed. The problem I am facing is determining which button was pressed. If I use: int ID = iv.getId(); When I click on ...
rick's user avatar
  • 181
16 votes
3 answers
34k views

onTouchListener not working

I have the following code in my activity. In my xml, the video view is inside the linear layout. However, when the view is clicked, the onTouchListener never fires. I tried changing the ...
yellavon's user avatar
  • 2,861
16 votes
3 answers
43k views

Android move view on touch event

I would like to move two different views into my layout, so that an user can display it like his wishes. So far I've made the following code to handle the touch event: this.viewEvent....
Manitoba's user avatar
  • 8,602
16 votes
2 answers
32k views

how to implement both ontouch and also onfling in a same listview?

i have a listview and implemented onclick and also onfling.problem is when i do fling(swipe left to right), onclick event of listview is also getting executed.How to overCome this problem? how to ...
Ads's user avatar
  • 6,701
16 votes
2 answers
21k views

A View's onTouchListener vs onTouchEvent

What is the difference between a view's onTouchEvent : public class MyCustomView extends View { // THIS : @Override public boolean onTouchEvent(MotionEvent event) { return super....
topher's user avatar
  • 1,357
15 votes
9 answers
13k views

Animatedly reduce button size on press and regain it's size on release

I want a to create a button that changes size (little bit smaller) when it's pressed, and after the button is released again the size should change back to normal size.I am using Scale xml to achieve ...
user2028's user avatar
  • 163
15 votes
6 answers
29k views

How to catch double tap events in Android using OnTouchListener

I am trying to catch double-tap events using OnTouchListener. I figure I would set a long for motionEvent.ACTION_DOWN, and a different long for a second motionEvent.ACTION_DOWN and measure the time ...
benbeel's user avatar
  • 1,542
15 votes
3 answers
12k views

Android ACTION_MOVE Threshold

I'm writing an app that involves writing on the screen using one's finger, or eventually a stylus. I have that part working. On ACTION_DOWN, starts drawing; on ACTION_MOVE, adds line segments; on ...
Erhannis's user avatar
  • 4,356
14 votes
2 answers
30k views

requestDisallowInterceptTouchEvent does not work unless selecting view first

According to android docs you can get your parent ViewGroup and call requestDisallowInterceptTouchEvent(true) on it to stop other things from interfering. This causes not only the immediate parent but ...
linuxfreakus's user avatar
14 votes
5 answers
1k views

Using the same onTouchEvent in various Activity

I am using an onTouchEvent for in my MainActivity.class. It's working fine : if the user make a double L with the fingers, I call a fragment. I would like to use this onTouchEvent in an other Activity ...
Jéwôm''s user avatar
  • 3,873
13 votes
4 answers
47k views

Add clickListner for button inside a cardView populated using a recyclerView

I have a cardView card_contents.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" ...
AnoopDV's user avatar
  • 305
13 votes
5 answers
5k views

SwipeListView only one item opened at a time

This question refers to the SwipeListView component found here: https://github.com/47deg/android-swipelistview After trying out several implementations and fixes I found on the web I decided to ...
Adrian Olar's user avatar
  • 2,893
12 votes
1 answer
8k views

How can I use onTouchListeners on each word in a TextView?

I would like to assign onTouchListeners to each word in a TextView. (Not to link to something on the internet, but just to continue the game logic inside the app). The general action of my game at ...
elliptic1's user avatar
  • 1,682
12 votes
6 answers
4k views

Get real x and y coordinates of users touch

I need to map onTouch event's X, Y coordinates to the Bitmap X, Y coordinates inside the ImageView to do this I use the following approach. However this approach seems to only work when I either: a)...
Sterling Duchess's user avatar
11 votes
3 answers
5k views

Android: How to determine character index of a touch event's position in TextView?

I have a TextView with an OnTouchListener. What I want is the character index the user is pointing to when I get the MotionEvent. Is there any way to get to the underlying font metrics of the TextView?...
Epaga's user avatar
  • 38.7k
11 votes
4 answers
23k views

Click, Press and Release event on Button

How can I detect clicked, pressed and released states of a Button. I want to perform different functions on these states. On click I want to call function1, on press I want to call function2 and on ...
Nitesh Kumar's user avatar
  • 5,390
11 votes
2 answers
1k views

OnTouchListener prevents visual feedback

I have a ListView which has an OnItemClickListener. On top of that, each row (CardView) has an OnTouchListener in order to implement a swiping gesture. The OnTouchListener reacts to ACTION_DOWN, ...
geecko's user avatar
  • 657
11 votes
4 answers
14k views

onTouchListener for entire screen

I have a screen filled with buttons, but want the onTouch-method to use the entire screen's coordinates. I first tried using a RelativeLayout with an onTouchListener, but never managed to make it "...
keyser's user avatar
  • 19k
11 votes
2 answers
20k views

Android OnTouch MotionEvent Actions

So I think I have a very simple issue but I can't seem to figure it out. I have an ImageView and I am using it's setOnTouchListener method (OnTouch). How can I differentiate between the ACTION_DOWN ...
ᴛʜᴇᴘᴀᴛᴇʟ's user avatar
11 votes
11 answers
6k views

android: ZoomPicker breaks onTouchListener

I've got a webview which makes use of the built in zoom controls, as follows: wv = new WebView(this); wv.getSettings().setBuiltInZoomControls(true); Note: this activates two main functions - pinch-...
tabjsina's user avatar
  • 1,592
10 votes
3 answers
8k views

Bound a View to drag inside RelativeLayout

I have created a draggable view inside RelativeLayout. But it seems to go beyond the RelativeLayout. I simply want to make a View draggable inside ViewGroup And this view is draggable according to ...
Zar E Ahmer's user avatar
  • 34.2k
10 votes
3 answers
19k views

Hide keypad in android while touching outside Edit Text Area

I know that the code for dismiss tyhe keypad in android is InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myEditText....
Nithin Michael's user avatar
10 votes
1 answer
6k views

Difference between OnTouchListener and OnClickListener

I made an app which implements a View.OnTouchListener. But when I uploaded it to Android Market (Google Play Store), I got the following message: This apk requests 1 features that will be used for ...
Sandy's user avatar
  • 2,572
10 votes
4 answers
684 views

Button left in highlighted state with touchListener and clickListener

I'm having a problem with my Button staying in a highlighted state, after doing the following: public class MainActivity extends AppCompatActivity { @SuppressLint("ClickableViewAccessibility") ...
Whitebear's user avatar
  • 1,781
10 votes
3 answers
6k views

How to Implement OnTouch Listener in XML

As i know we can define onClick tag in xml after writing in xml we can use in java code easily by name that specify in xml eg <Button android:id="@+id/mybutton" android:layout_width="...
Attaullah's user avatar
  • 3,956

1
2 3 4 5
29