Hey i dont know if you will read this or not its almost two years. But i 
want to the exact same this i using AsyncTask to write strings to my 
socket. I want to press and hold my button and it should repeat sending the 
string to the socket how i can use this handler while im using execute() 
with my object from AsyncTask class?

On Wednesday, 25 August 2010 01:22:29 UTC+5, Jason Braucht wrote:
>
> http://developer.android.com/resources/articles/timed-ui-updates.html 
> describes how to use android.os.Handler to create repeating events.  I 
> used that along with a an OnTouchListener to repeat the button's 
> action every 100ms until the button is released. 
>
> Below is a snippet of code that demonstrates the basic idea.  If you 
> find any flaws with this or come up with a better approach, please let 
> me know. 
>
> public MyActivity extends Activity 
> { 
>     private Handler mHandler = new Handler(); 
>
>     private Runnable mUpdateTask = new Runnable() 
>     { 
>         public void run() 
>         { 
>             Log.i("repeatBtn", "repeat click"); 
>             mHandler.postAtTime(this, SystemClock.uptimeMillis() + 
> 100); 
>         } 
>     }; 
>
>     public void onCreate(Bundle savedInstanceState) 
>     { 
>         super.onCreate(savedInstanceState); 
>         setContentView(R.layout.main); 
>
>         Button repeatButton = (Button) 
> findViewById(R.id.repeatButton); 
>         repeatButton.setOnTouchListener(new OnTouchListener() 
>         { 
>             public boolean onTouch(View view, MotionEvent motionevent) 
>             { 
>                 int action = motionevent.getAction(); 
>                 if (action == MotionEvent.ACTION_DOWN) 
>                 { 
>                     Log.i("repeatBtn", "MotionEvent.ACTION_DOWN"); 
>                     mHandler.removeCallbacks(mUpdateTask); 
>                     mHandler.postAtTime(mUpdateTask, 
> SystemClock.uptimeMillis() + 100); 
>                 } 
>                 else if (action == MotionEvent.ACTION_UP) 
>                 { 
>                     Log.i("repeatBtn", "MotionEvent.ACTION_UP"); 
>                     mHandler.removeCallbacks(mUpdateTask); 
>                 } 
>                 return false; 
>             } 
>         }); 
>     } 
> } 
>
>
> On Aug 23, 6:15 pm, ls02 <[email protected]> wrote: 
> > Does android have auto repeat button that constantly sends events when 
> > the button is pressed down? If it does not have such button how do I 
> > implement it?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to