Wednesday 13 June 2018

how to show html code as text in android studio 2.3.3




want put html code like code tutorial description so
i want to show html code in activity like given website link below




At the end of the HTML tutorial, you can find more than 200 examples.



With our online editor, you can edit and test each example yourself.


Answer




i want to show html code in a textview then click on button show output of html code......... – Sachin Srivastava




add below library in your build.gradle file




//for html to text
compile 'org.jsoup:jsoup:1.8.3'


and



TextView txt_htmltext;
Button btn;


txt_htmltext = (TextView) findViewById(R.id.txt_htmltext);
btn = (Button) findViewById(R.id.btn);

txt_htmltext.setText(R.string.temp_html_text);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txt_htmltext.setText(html2text(txt_htmltext.getText().toString()));
}

});

public String html2text(String html) {
try {
return Jsoup.parse(html).text();
} catch (Exception ignored) {
return "";
}
}



res/values/string.xml:



   Page Title   

This is a Heading

This is a paragraph.

]]>



XML code:



    android:id="@+id/layout"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="3sp">

android:id="@+id/txt_htmltext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:gravity="center|left"
android:text="@string/temp_html_text"/>

android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="html to text"/>




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...