Home > Software design >  How to dismiss a MaterialAlertDialog when a hyperlink is clicked?
How to dismiss a MaterialAlertDialog when a hyperlink is clicked?

Time:10-14

Is there a way to dismiss/cancel a MaterialAlertDialog when a hyperlink inside the message was clicked? Currently the browser is open and when you returned to the app the dialog is still open. For the buttons there is a listener where you can dismiss/cancel the dialog.

What I want to achieve is to close the dialog when the link is clicked.

CodePudding user response:

  1. add onClickListener to TextView containing hyperlink
  2. use onResume() method to close dialog after you return to it

CodePudding user response:

After reading a bit about setLinkMovementMethod I thought about somethink like:

textView.setLinkMovementMethod(new TextViewLinkHandler() {
   // do my stuff ... 
   // if left blank, nothing will happen on click at the link, so leave it blank to do nothing
})

With the mentioned TextViewLinkHandler()

public abstract class TextViewLinkHandler extends LinkMovementMethod {
  // add a method to handle the click
  // extract the url and open it
  // then dismiss the dialog
}

But maybe this is not the right approach. What did you think?

  • Related