Wednesday, April 13, 2011

How to dismiss your non-modal dialog, when touched outside dialog region

When you implement your dialog as non-modal dialog, means when your dialog is shown, you can interact with other elements on the screen, in such case, you might be interested to dismiss the dialog, when user touches/press/interacts with other elments on the screen. The following steps will help you to reeceive for the touch events outside your non-modal dialog.

1 - Set the flag-FLAG_NOT_TOUCH_MODAL for your dialog's window attribute

Window window = this.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

2 - Add another flag to windows properties,, FLAG_WATCH_OUTSIDE_TOUCH - this one is for dialog to receive touch event outside its visible region.

3 - Override onTouchEvent() of dialog and check for action type. if the action type is
'MotionEvent.ACTION_OUTSIDE' means, user is interacting outside the dialog region. So in this case, you can dimiss your dialog or decide what you wanted to perform.

public boolean onTouchEvent(MotionEvent event)
{

if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
System.out.println("TOuch outside the dialog ******************** ");
this.dismiss();
}
return false;
}

7 comments:

  1. This is very helpful tutorial..thanks a lot for sharing..

    ReplyDelete
  2. Hi, I Just Want to say that this post is very well written and very informative too . Thanks for sharing this with us .
    Machine learning training institute

    ReplyDelete
  3. I want to appreciate you for the efforts that you have put in writing this blog. More knowledge with simpler words. Being a content writer, I really like the quality of the content. I also have a team of academic writers including subject matter experts that provides the Architecture Homework Help for students looking for the online assignment help.

    ReplyDelete
  4. When you is unable to demonstrate good writing talents in your papers at any time in Australia, choose to use Solidworks assignment help online services. Without writing a single word, it is the greatest approach to get expert help for writing an effective and productive assignment.

    ReplyDelete
  5. Premium dissertation editing and proofreading services are available at UK-based dissertation proofreading services Allow our knowledgeable proofreaders to polish your thesis. Obtain flawless outcomes and submit with assurance.

    ReplyDelete
  6. The fees may vary depending on factors such as the exam level, geographical location, and registration deadlines. Candidates need to stay informed about the ACCA exam fees to effectively plan and budget for their professional development in the field of accountancy.

    ReplyDelete
  7. This blog provides clear steps for dismissing non-modal dialogs, aiding developers efficiently. Great resource! For support in overcoming addiction, consider visiting Vikalp Rehab, a trusted "nasha mukti kendra near me."





    ReplyDelete