0

first of all sorry for my language. i want to show dialog which has message like this ," hello , your app license about the expire. tap "here" and buy new license! " and also has "do not show again" button and " remind me later" button. i want to make that "here" word clickable. when user click it ,i redirect him to the link. for example https://stackoverflow.com/ thanks for your interests ! have a nice day =)

i tried this but did not work. when i tap "here" after dialog shown, nothing happening. my dialog is here,

 AlertDialog.Builder alertLicenseExpire = new AlertDialog.Builder(TabActivity.this);
    alertLicenseExpire.setTitle(getString(R.string.dialog_warning_license_title));
    alertLicenseExpire.setMessage(String.format(getString(R.string.dialog_warning_license_exparation),getString(R.string.url_here)));
    alertLicenseExpire.setCancelable(false);
    alertLicenseExpire.setPositiveButton("remind me later", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            handler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(),"I am going to do something good..",Toast.LENGTH_SHORT).show();                    }
            });
        }
    });
    alertLicenseExpire.setNegativeButton("Do not show again", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(),"You won't see that massage again",Toast.LENGTH_SHORT).show();                    }
            });
        }
    });
    alertLicenseExpire.show();

and here my strings ,

<string name="dialog_warning_license_title">Warning of License Expiration</string>

<string name="dialog_warning_license_exparation">Your license is about expire   In order to continue to use app, please click %s for purchase a new license.</string>

   <string name="url_here"><a href="https://stackoverflow.com/">here</a><string>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Use Linkify:

    TextView tv = (TextView) findViewById(R.id.sample_text);
    tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String msg = "https://www.google.com/";
            final SpannableString msgLink = new SpannableString(msg);
            Linkify.addLinks(msgLink, Linkify.ALL);

            final AlertDialog dialog = new AlertDialog.Builder(Tests.this)
                    .setPositiveButton(android.R.string.ok, null)
                    .setMessage( msgLink )
                    .create();

            dialog.show();

            ((TextView)dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
        }
    });

P.S. well, i used a textView to achieve the OnClickListener, but obsiously you can do the same thing with whatever you want, i tested it and it works, good luck dude, keep coding!

Source: https://stackoverflow.com/a/3367392/10728976

Saltae
  • 183
  • 1
  • 2
  • 11