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

Pseudo code answer to clarify the above comments. How to have the MySimpleGestureListener’s onTouch method called. public class GestureExample extends Activity { protected MyGestureListener myGestureListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myGestureListener = new MyGestureListener(this); // or if you have already created a Gesture Detector. // myGestureListener = new MyGestureListener(this, getExistingGestureDetector()); // Example of … Read more

Android – Hold Button to Repeat Action

This is more independent implementation, usable with any View, that supports touch event: import android.os.Handler; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; /** * A class, that can be used as a TouchListener on any view (e.g. a Button). * It cyclically runs a clickListener, emulating keyboard-like behaviour. First * click is fired immediately, … Read more

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

You are right, I believe every scrolling container intercepts touch events, but you can prevent it. You can put a touch listener on your layout: public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: pager.requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: pager.requestDisallowInterceptTouchEvent(false); break; } }

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

A classic hack for situations like this is to use a handler and postDelayed(). In your adapter: private int lastFocussedPosition = -1; private Handler handler = new Handler(); public View getView(final int position, View convertView, ViewGroup parent) { // … edittext.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { handler.postDelayed(new … Read more

OnTouchEvent not working on child views

The problem is the order of operations for how Android handles touch events. Each touch event follows the pattern of (simplified example): Activity.dispatchTouchEvent() ViewGroup.dispatchTouchEvent() View.dispatchTouchEvent() View.onTouchEvent() ViewGroup.onTouchEvent() Activity.onTouchEvent() But events only follow the chain until they are consumed (meaning somebody returns true from onTouchEvent() or a listener). In the case where you just touch somewhere … Read more

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

You can use the code bellow to achive your request: Method to test view bounds (used in code beloow) Rect outRect = new Rect(); int[] location = new int[2]; private boolean isViewInBounds(View view, int x, int y){ view.getDrawingRect(outRect); view.getLocationOnScreen(location); outRect.offset(location[0], location[1]); return outRect.contains(x, y); } Testing with two TextView final TextView viewA = (TextView) findViewById(R.id.textView); … Read more

Image in Canvas with touch events

You can use this: import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.View; public class MyImageView extends View { private static final int INVALID_POINTER_ID = -1; private Drawable mImage; private float mPosX; private float mPosY; private float mLastTouchX; private float mLastTouchY; private int mActivePointerId = INVALID_POINTER_ID; private ScaleGestureDetector … Read more