Injury
Injury

Reputation: 143

How to detect no touch on a view after some seconds?

I have a small view (call it "user-object") which overlap the background view (call it map). I can drag the "user-object".

I want the "user-object" automatically move to "mid-point" (screen_width/2, screen_height/2) after some seconds (for instance 4s) if three is no touch/drag.

Upvotes: 0

Views: 243

Answers (2)

Jibran Khan
Jibran Khan

Reputation: 3256

An example using Handler

Handler mHandler;
public void useHandler() {
   mHandler = new Handler();
   mHandler.postDelayed(mRunnable, 1000);
  }

  private Runnable mRunnable = new Runnable() {

    @Override
    public void run() {
               // Perform this here 
               "user-object" automatically move to "mid-point" (screen_width/2, screen_height/2)
      mHandler.postDelayed(mRunnable, 1000);
    }

After a drag/touch event is triggered, again apply handler.postDelayed().

Upvotes: 0

lichangadd
lichangadd

Reputation: 48

You can send a delay(3000ms) message at the beging and move "user-object" in the Handler's callback,If "user-object" was touched,remove the message

Upvotes: 1

Related Questions