Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alert box problem

 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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..


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic