Android Motionevent get long press time long

Source: Internet
Author: User

Ideas:

1. Record Action_down ax, ay coordinates;

2. In the action_move to determine whether to move, move the record time is canceled, no movement on the record;

3. Record the time, press the coordinates, the movement coordinates display in TextView AA, BB, CC respectively;

Statement

 1  public  class  mainactivity extends   actionbaractivity {  2  private  static   TextView AA, BB, CC;  3  private  float   Atime;  4  private  float   AX, AY;  5  private  boolean  mpressbreak = false ; 

Specified

1 aa = (TextView) Findviewbyid (r.id.textview1); 2 bb =3 cc = (TextView) Findviewbyid (R.ID.TEXTVIEW3);

Get a long press time

1 @Override2      Public Booleanontouchevent (Motionevent event) {3         //TODO auto-generated Method Stub4         Super. Ontouchevent (event);5String str = "";6         Switch(Event.getaction ()) {7          CaseMotionevent.action_down:8AX =event.getx ();9AY =event.gety ();Tenstr = string.valueof (AX) + "," +string.valueof (AY); One Bb.settext (str); AMpressbreak =false; -              Break; -          CaseMotionevent.action_move: the  -Atime = (Event.geteventtime ()-event.getdowntime ())/1000; -str = string.valueof (Event.getx ()) + "," -+string.valueof (Event.gety ()); +             if((Math.Abs (Event.getx ()-AX)) > 10) -|| (Math.Abs (Event.gety ()-AY) > 10)) { +Atime = 0; AMpressbreak =true; at             } -              Break; -  -         } -  -         if(!mpressbreak) { inAa.settext (String.valueof (int) (Atime )); - Cc.settext (str); to         } +  -         return true; the}

Android Motionevent get long press time long

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.