developer
developer

Reputation: 329

how to convert plain text into html text in android?

I am uploading the text to server, i just want to upload those string in html format example

input:

Do you know the relation between two eyes...??? They never see each other... BUT

  1. They blink together.
  2. They move together.
  3. They cry together.
  4. They see together.
  5. They sleep together. They share a very deep bonded relationship...

However, when they see a pretty woman, one will blink and another will not...

            sendtext = adding_textjoke.getText().toString();


            //String htmlString = Html.toHtml(sendtext);

            String str = "(?i)\\b((?:https?://|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'\".,<>?«»“”‘’]))";
            Pattern patt = Pattern.compile(str);
            Matcher matcher = patt.matcher(sendtext);
            sendtext = matcher.replaceAll("<a href=\"$1\">$1</a>");
            System.out.println(sendtext);
            Log.e("sendtext", sendtext);
            new AddJokesTask().execute(sendtext);

How to do this in android?

Upvotes: 2

Views: 4855

Answers (2)

kirti
kirti

Reputation: 71

SpannableStringBuilder text = (SpannableStringBuilder) contentView.getText();
String htmlEncodedString = Html.toHtml(text);

Upvotes: 0

Zeeshan Ahmed
Zeeshan Ahmed

Reputation: 1187

You can do it like this

SpannableString contentText = (SpannableString) contentView.getText();
 String htmlEncodedString = Html.toHtml(contentText)

Upvotes: 2

Related Questions