Ambitious Person
Ambitious Person

Reputation: 295

How i make String + URL in AlertDialog with String is not clickable and URL is clickable

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.

Upvotes: 2

Views: 1124

Answers (1)

Santosh Kathait
Santosh Kathait

Reputation: 1444

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()); 

Upvotes: 2

Related Questions