• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Alert box problem

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Since 2 days I am facing a strange problem. I am making an application where I need alert dialogue with two button (e.g.) Yes/No
I am calling one method (in which I have written stuff for alert box) on click event of a button. The alert box code works fine.As far as my knowledge is concern the next line in calling function will get executed only after the called function finishes it's task.

Here is a code to review...
Below is Button's click event from where I am calling a function validateFields();

Below is code for validateFileds();


For a moment forget that yes/no button code.Just focus on OK button code.

Now this code gives alert whenever 'to' (EditText's object) is empty.
But before I press OK control comes out of validateFields() and executes the next line in onClick method.

Why this is happening is not clear to me.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you show an alert box, the code won't stop executing there. The code will continue to execute even if the alert is still visible...
 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:When you show an alert box, the code won't stop executing there. The code will continue to execute even if the alert is still visible...



Hi Ankit, Thank you for the reply. But I think then alert box is of no use.Now if I want to use yes/no alert box and I need to do some action on basis of the button which is pressed by user then in that case what should I do?

I know there is onClick method for positive and negative button. But what to do to pause the control of a program.
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you said yourself, you have an event listener to execute some code based upon the button clicked in the alert box. Still if you want "pause" the execution till a button is pressed in the alert box, you can use the normal wait and notify mechanism of java...
 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Ankit

Again thanking you for reply.As you told me I tried wait and notify methods.It partially solve my problem.
The new problem is alert box's show() method is not displayed.Using LogCat I traced the flow, then I came to know that thread works fine but some how code fails to display alert box.

Following is the code with thread implementation.


Below is validateFields() method..


 
reply
    Bookmark Topic Watch Topic
  • New Topic