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:
<string name="temp_html_text"><![CDATA[<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>This is a Heading</h1> <p>This is a paragraph.</p> </body> </html>]]></string>
XML code:
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="3sp">
<TextView
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"/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="html to text"/>
</LinearLayout>