1. Are you ready for the Galaxy S20? Here is everything we know so far!

programming question

Discussion in 'Android Development' started by Someonation, Sep 20, 2011.

  1. Someonation

    Someonation Lurker
    Thread Starter

    how do i add a click listener to the screen?
    to be more spesific i want to know the coordinates where he left the screen (if he moved his finger while touching the screen)
     


  2. jonbonazza

    jonbonazza Android Expert

    implement an OnTouchListener interface, then implement the associated method, like so:
    Code (Text):
    1.  
    2. public void onTouch(MotionEvent e)
    3. {
    4.      if(e.getAction() == MotionEvent.ACTION_UP)
    5.      {
    6.           float x, y;
    7.           x = e.getX();
    8.           y = e.getY();
    9.       }
    10. }
    11.  
     
  3. Someonation

    Someonation Lurker
    Thread Starter

    How do I refer the screen to a view? so the method will know on what the MotionEvent action was done?
     
  4. jonbonazza

    jonbonazza Android Expert

    You need to Create an instance of the layour containing the controls and then use the setOnClickListener() method to assign the listener to the layout.
     
Loading...
Similar Threads - programming question
  1. workbench
    Replies:
    0
    Views:
    160
  2. montecarlo1987
    Replies:
    12
    Views:
    396
  3. Gleis
    Replies:
    4
    Views:
    813
  4. startac4
    Replies:
    18
    Views:
    1,061
  5. MoodyBlues
    Replies:
    9
    Views:
    755
  6. Ipokor
    Replies:
    1
    Views:
    284
  7. arpan_de
    Replies:
    0
    Views:
    280
  8. Adhik123
    Replies:
    2
    Views:
    523
  9. Luke Drillbrain
    Replies:
    4
    Views:
    340
  10. Biffos
    Replies:
    0
    Views:
    358

Share This Page

Loading...