-3

How to perform touch event and click event on a single view please give a proper suggestion

I would very thankful to you.

hareesh J
  • 520
  • 1
  • 6
  • 21
  • http://developer.android.com/reference/android/view/View.OnClickListener.html http://developer.android.com/reference/android/view/View.OnTouchListener.html – Naddy Mar 26 '14 at 10:22

1 Answers1

1

You can do anything in the touch event like i will show one example for the touch You can achieve the all things like single press long press on fling etc.... If you have any doubt comment it... Sample is....

 public class MainActivity extends Activity {
private CalendarView view ;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    new GestureDetector(new GestureListener());
    view = (CalendarView)findViewById(R.id.calendar);

}
@Override
public void onConfigurationChanged(Configuration newConfig) {       
    super.onConfigurationChanged(newConfig);
}
class GestureListener implements OnGestureListener
{

    @Override
    public boolean onDown(MotionEvent e) {
        System.out.println("Down List");
        return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        System.out.println("Fly List");
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        System.out.println("Long press");

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2,
            float distanceX, float distanceY) {

        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {

        System.out.println("Press List");

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        System.out.println("Single Tap List");
        return false;
    }

}
  }
Naveen Kumar Kuppan
  • 1,424
  • 1
  • 10
  • 12