Sunday 15 February 2015

multithreading - How to wait button clicks for a while in android -


I am developing an application for the blind

I have 4 screen-size buttons ( Overlapped). One button at each stage of the program will be clickable and each button will have more than one function.

My program starts with a voice (Android TTS engine). Like "Please touch screen to X" after this step I want to wait 3 seconds for button click, if do not click to vocal "Please touch on the screen" and for the job y Wait for 3 seconds. (X and Y are the first button jobs).

The button should do one of them according to the touch screen. But how can I wait 3 seconds to click on the button and continue to talk about the next options and wait 3 seconds again.

If the first button is clicked, it will disappear-button 2 will be clickable - and TTS engine will start vocalizing the other button options. The application will work like this, but I'm stuck in the wait button click part.

I would advise you to use android.os.Handler instead, in your case you do something like this Can:

  create on public zeros () {this.handler = new handler) playTheVoiceOfThingX () viewToTap.setOnClickListener (New OnClickListener) {@Override Public Zero Onclick (see V) { DoThingX ();}}); Handler.post Delayed (New Preparation Tight YTask (), 3000); } Class PrepareThingYTask () executes Runnable {viewToTap.setOnClickListener (New OnClickListener () {@Override Public Zero Click on () {doThingY ();}}); Handler.post Delayed (new PrepareThingZTask (), 3000); } Class PrepareThingZTask () executes Runnable {....}  

A good reminder, runner executed by handler can be executed in UIThread, no heavy work on it , Or different loops to run it

Regards


No comments:

Post a Comment