1. Download our Official Android App: Forums for Android!

Apps programming question

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

  1. Someonation

    Someonation Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Sep 20, 2011

    Sep 20, 2011
    2
    0
    5
    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)
     

    Advertisement

  2. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    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
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Sep 20, 2011

    Sep 20, 2011
    2
    0
    5
    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
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    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.
     

Share This Page

Loading...