2

I am showing Alert-Dialog in which i have "Terms & Conditions" and at last there is Text on which click i want to fetch a URL. I don't want to show URL in String instead of URL i want to show String in different color or size to know user.

AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setTitle("My App Title");
   builder.setPositiveButton(R.string.next,
     new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int id) {
       // code goes here

       User u = new User();
       u.setTncAccpted(true);
       u.setFirstRun(true);
       u.commit(SelectionApp.this);
       viewedWeb = false;
       dialog.dismiss();
      }

     });
   try {
    builder.setMessage(Html
    .fromHtml("<p>My Text is going here....</p><p>My other String is going here....</p>By proceeding you are accepting <a href=\"\">Terms and Conditions.</a>"));

    AlertDialog dialog = builder.create();
    if (dialog == null)
     return;
    dialog.show();
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(false);
((TextView) dialog.findViewById(android.R.id.message))
  .setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub

    Intent termAndConditionIntent = new Intent(
    SelectionWhiteApp.this, ViewWeb.class);
    startActivity(termAndConditionIntent);
       }
      });

   } catch (Exception e) {
    // TODO: handle exception
   }

Now my Whole text is Clickable but i only want to "Terms and Conditions" Clickable, and when it click open particular link.

Ambitious Person
  • 295
  • 1
  • 3
  • 15
  • No Ulhas, not your whole page is clickable. Its just "Terms and Conditions". Though it throwing error on click. I did "Run code Snippet". – Kishor Pawar May 07 '15 at 06:57
  • Sorry @KishorPawar but i didn't give any url inside. Code is changed here i didn't put original but you ll get what i want to do. – Ambitious Person May 07 '15 at 07:01
  • What I want to say is that your code seems right. just "Terms and Conditions" is clickable and not the whole page. – Kishor Pawar May 07 '15 at 07:07

1 Answers1

2

I am not sure whether it will work or not but you can try this

text.setText(Html.fromHtml("<bMy Text is going here....</b>" +
                "<a href=\"http://www.example.com\">Terms and Conditions.</a> "));
 text.setMovementMethod(LinkMovementMethod.getInstance()); 
Santosh Kathait
  • 1,444
  • 1
  • 11
  • 22