0

I have alert dialog box having two button a. OK b. No

If user press ok some operation is performed else some other action is performed .

What I am looking for is that to check if user has entered any button or not if he has not, After few second I wish to send some message. Would any one help me with this ??

Kirthan
  • 11
  • 5
  • So let me get this straight. You want to perform an action after a user has not done anything on the alert dialog right? Say he presses the back button – Zuko Nov 11 '15 at 12:47
  • Welcome to StackOverflow! Right now, your question is quite broad! Please have a look at the [how to ask](http://stackoverflow.com/help/how-to-ask) section to see how you could improve your question! – jkalden Nov 11 '15 at 12:48
  • @olucode: Yeah it is like server is expecting reply from client say Y/N , BUT AT THE SAME TIME CLIENT failed to respond , then I wish to send the message from client to server after few second ....... – Kirthan Nov 12 '15 at 03:56

1 Answers1

1

You can use a Timer after your AlertDialog.show() method.

yourDialog.show();

final Timer timer = new Timer();
timer.schedule(new TimerTask() {
    public void run() {
        if (yourDialog.isShowing()) {
            // Send some message
            timer.cancel();
        }
    }
}, 2000); // Seconds in milliseconds

Also check this question for other possibilities: Android close dialog after 5 seconds?

Community
  • 1
  • 1
Bona Fide
  • 714
  • 1
  • 9
  • 33
  • thank for that reply, i didnt understand the use of ...........> if(dialog.isShowing()) .... but if am right is that condition is to ,check whether user has entered button or not ??? – Kirthan Nov 12 '15 at 04:40
  • The method `Dialog.isShowing()` just returns _whether the dialog is currently showing_. I assume that the dialog get close if one of the buttons got clicked. Nice to hear, that you got it! :-) – Bona Fide Nov 12 '15 at 08:31
  • is there any way to check if user has clicked either YES or NO button. I want to SEND SOME MESSAGE only if there is no input from user (i.e if he hasn't entered yes or no then send some message) – Kirthan Nov 12 '15 at 08:57
  • You can set a boolean variable for example `isClicked` which you change to true in the `onClickListener` of the OK or NO action. Then you can check for the value in the timer. But don't you close the Dialog after the NO or OK action got clicked? – Bona Fide Nov 12 '15 at 09:11
  • yes I do want to close it, but at same time I want to make sure that if user does not click any one of option then do send some message to server. i.e if positive button = some action – Kirthan Nov 12 '15 at 09:55
  • i.e if positive button = some action else = some other action . finally within timer see if user has entered yes or no if he hasn' t then send message to server or else just close dialog box !!!!! – Kirthan Nov 12 '15 at 10:02
  • Maybe you misunderstood me, my question was if your Dialog get closed when you click on the Yes or No button? If so, there is no need to do it otherwise than in my answer above. :) – Bona Fide Nov 12 '15 at 10:08