0

I am new in android. I want to use the translate animation in android. I want that the red rounded image comes from center of the layout. It comes . But i want that the red rounded image comes back from the center image which color is green. Thanks in Advance.enter image description here

3
  • How do You show the dialog? Have You tried Handler.postDelayed()?
    – sandrstar
    Jul 23, 2013 at 9:19
  • no i dont know about Handler.postDelayed() can you provide me the code for this problem ??? thanks in advance Jul 23, 2013 at 9:22
  • @GauravMehta You can't edit your previous question completely and post a new question. if you have a question, ask a new question.
    – Bishan
    Oct 9, 2013 at 8:16

3 Answers 3

2
final AlertDialog.Builder dialog = new AlertDialog.Builder(this)
 .setTitle("Auto-closing Dialog")
 .setMessage("After 10 second, this dialog will be closed");

dialog.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int whichButton) {
        // tasks to do when Confirm clicked
    }
});     
final AlertDialog alert = dialog.create();
alert.show();

// Hide after 10 seconds
final Handler handler  = new Handler();
final Runnable runnable = new Runnable() {
    @Override
    public void run() {
        if (alert.isShowing()) {
            alert.dismiss();
        }
    }
};

alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        handler.removeCallbacks(runnable);
    }
});

handler.postDelayed(runnable, 10000);
5
  • Why would you post two answers? Just curious mostly. ;-) Jul 23, 2013 at 9:32
  • @SiddharthLele different approaches.
    – Bishan
    Jul 23, 2013 at 9:34
  • Hmmm.. Okay. ;-) I am not complaining. But I just thought it curious when both could have been in one. That's all mostly. Jul 23, 2013 at 9:35
  • @SiddharthLele Deleted other one since user accepted this one.
    – Bishan
    Jul 23, 2013 at 9:35
  • 1
    @GauravMehta it's pleasure to me :)
    – Bishan
    Jul 23, 2013 at 9:40
2

I would recommend you Handler and it's postDelayed method. So the code should look like this

Handler handler = new Handler();
handler.postDelayed(new Runnable() {

    public void run() {

        if(dialog != null && dialog.isShowing())
        dialog.dissmiss();
    }
}, 10000);

where handler should be created on the UI thread.

1

Create a handler, somewhere in activity oncreate method as follows:

handler = new Handler();

Now, show the dialog.

Later use this handler to dismiss dialog after 10 seconds as follows:

handler.postDelayed(new Runnable() {

   public void run() {
       if (dialog.isShowing())           
          dialog.dismiss(); // dismiss dialog

   } 
}, 10000);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.