aspose file tools*
The moose likes Android and the fly likes Alert box problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Alert box problem" Watch "Alert box problem" New topic
Author

Alert box problem

Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
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.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
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

Joined: Aug 03, 2008
Posts: 9305
    
  17

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

Joined: Jan 30, 2010
Posts: 252
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..


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Alert box problem