Can I use another method to show my text? - android

I am using below lines of code to show html pages on my application but my app is too slow when scrolling.
Can I use another method to show the text? Can it be by html page or another method? or use listview to show my text?
or is it necessary to create layout for every text page?
Thanks.
ck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/ck.html");
((Button)findViewById(R.id.cb)).setVisibility(View.GONE);((Button)findViewById(R.id.geri)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.db)).setVisibility(View.GONE); ((Button)findViewById(R.id.bb)).setVisibility(View.GONE); ((Button)findViewById(R.id.ck)).setVisibility(View.GONE);
}
});
cb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {

You Can Use This Library :-
https://github.com/PrivacyApps/html-textview
HtmlTextView is an extended TextView component for Android, which can load HTML and converts it into Spannable for displaying it. It is a replacement for usage of the WebView component, which behaves strange on some Android versions, flickers while loading, etc.

My issue solved using below code you can try this one:
// get our html content
String htmlAsString = getString(R.string.html);
Spanned htmlAsSpanned = Html.fromHtml(htmlAsString); // used by TextView
// set the html content on the TextView
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(htmlAsSpanned);
<resources>
<string name="html">
<![CDATA[
<h1>Main Title</h1>
<h2>A sub-title</h2>
<p>This is some html. Look, here\'s an <u>underline</u>.</p>
<p>Look, this is <em>emphasized.</em> And here\'s some <b>bold</b>.</p>
<p>This is a UL list:
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<p>This is an OL list:
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
</string>
</resources>
Hope this will help you if not than inform me

Related

how to change html of dialog dynamically in onsen

I'm trying to dynamically change the html content of a dialog of onse.ui, but it is not working for me, my code is as below:
Here my html code.
<ons-template id="popupFechaCalendario.html">
<ons-dialog style="height: 300px;" var="naviDialog" cancelable>
<ons-navigator var="myNav">
<ons-toolbar inline>
<div class="center contenedorPopup" id="popupFechaCalendario_fecha">html content</div>
</ons-toolbar>
</ons-navigator>
</ons-dialog>
</ons-template>
And here my Javascript code.
$("#popupFechaCalendario_fecha").html("some html...");
ons.createDialog('popupFechaCalendario.html').then(function(dialog) {
dialog.show();
});
I have also tried like,
ons.createDialog('popupFechaCalendario.html').then(function(dialog) {
dialog.on("preshow", function(e) {
$("#popupFechaCalendario_fecha").html("some html...");
});
dialog.show();
});
In advance thank you very much to anyone who can help me

Decode html before showing it in AlertDialog Android

I want to decode text before showing it to AlertDialog. So I used Html.fromHtml(String), but It is not working my case. I have also tried escapeHtml() but still no result.
My String is :
<div> The pampiniform plexus is a network of many small veins found in the human male spermatic cord. It is formed by the union of multiple spermatic veins from the back of the testis and tributaries from the epididymis.<br /> <br /> &nbsp;</div> <div> The veins of the plexus ascend along the cord in front of the ductus deferens. Below the superficial inguinal ring they unite to form three or four veins, which pass along the inguinal canal, and, entering the abdomen through the deep inguinal ring, coalesce to form two veins. These again unite to form a single vein, the testicular vein, which opens on the right side into the inferior vena cava, at an acute angle, and on the left side into the left renal vein, at a right angle.The pampiniform plexus forms the chief mass of the cord.<br /> <br /> &nbsp;</div> <div> In addition to its function in venous return from the testes, the pampiniform plexus also plays a role in the temperature regulation of the testes. It acts as a heat exchanger, cooling blood in adjacent arteries. An abnormal enlargement of the pampiniform plexus is a medical condition called varicocele.</div> <br>
My Code :
TextView tv = new TextView(getApplicationContext());
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(lstDescription.get(position)).toString());
final AlertDialog alertDialog = new AlertDialog.Builder(RandomQuestion.this).create();
alertDialog.setView(tv);
alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
alertDialog.cancel();
}
});
alertDialog.show();
How to show it as Html Text ???
to decode Html String you can use Html.fromHtml()
like
Html.fromHtml((String) htmlCode).toString();
ok then try this way :
String str = lstDescription.get(position)).toString().replace("<","<").replace(">",">").replace("nbsp;", " ");
tv.setText(Html.fromHtml(str );

URLSpans in WebView?

I need to push text into WebView. But there are a lot of different HTML tags in this text and I want to parse it before.
Spanned html = Html.fromHtml(texts.get(i));
But I need to change URLs in the text to call one function in my activity. In TextView I may do it like that:
ClickableSpan[] items = spans.getSpans(0, spans.length(), ClickableSpan.class);
for (ClickableSpan s : items) {
final String url = ((URLSpan)s).getURL();
int spanStart = spans.getSpanStart(s);
int spanEnd = spans.getSpanEnd(s);
spans.removeSpan(s);
spans.setSpan(new URLSpan(url) {
#Override
public void onClick(View widget) {
//code for overriding onClick goes here
}
}, spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Is it possible to use Html.fromHTML() AND to change links in text to call my function when using WebView instead of TextView?
Not really, because WebView understands HTML, not a Spanned. You are welcome to try to convert the Spanned back into HTML via Html.toHtml(), but the round-trip conversion from HTML to Spanned to HTML is likely to make a hash of any complex formatting, because they are not complete HTML parsers or generators.
I would recommend that you find and use some Java library that is designed to parse and help you fix up HTML.

How to show html codes inside TextView or something else on Android?

How can I show html source as rendered in TextView or something else?
I tried this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.tv1);
String s = "<img src=\"http://images2.layoutsparks.com/1/146278/purple-lotus-lovely-dew.jpg\"/>";
Spanned sp = new SpannableString(s);
tv.setText(Html.toHtml(sp));
}
But I got:
HTML support in a TextView is pretty limited, but here is an example of some of the things you can do:
https://github.com/brianjolly/TextFun
The key is escaping the opening bracket in your strings.xml
<string name="fun_text">I like <font color=\'0x00b0f1\'>BLUE!</font> and <b> Bold</b> and <i> italic</i> and <u> underline</u></string>
And then resetting the text like so:
String styledText = tv.getText().toString();
tv.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
The beauty of open source is you can see what Html.fromHtml() supports in the android source here:
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/text/Html.java
If you're looking to do something more advanced take a look at WebView

Text viewed as HTML

Hey everyone this is a update from my previous question
https://stackoverflow.com/questions/6676440/android-showing-a-edittext-text-in-webview
I got the webview to see the text inside my Edit text field but its displaying it as text
this is the coding im using
case R.id.Preview:
Intent j = new Intent(this, Preview.class);
j.putExtra(com.afajje.htmlzero.Preview.URL,
myEditText.getText().toString());
startActivity(j);
}
return false;}
Want im trying to have it do is view the Edit text, text as HTML
For example if I put in the Edittext field
<html>
<head>
</head>
<body>
<p>This is a Preview</p>
</body>
</html>
In the web view itll just just the "This is a Preview"
Here ya go, a working demo:
package com.stackexchange.test;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.widget.EditText;
public class home extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText box = (EditText) findViewById(R.id.edittext);
String htmltext = "<b>This is bold. </ b> and <i> this is italic </ i>." ;
Spanned text = Html.fromHtml( htmltext );
box.setText( text );
}
}
You should see (except that I've edited the text in the app):
Try the below code to show the html text into the EditText.
String str = "<html><head></head><body><p>This is a Preview</p></body></html>";
editText = (EditText)findViewById(R.id.editText);
editText.setText(Html.fromHtml(str));
Well, in the editText, if you dont use "Html.fromHtml", the string will be display with the html tags. In a WebView, I really dont know what zou want to do...sorry

Categories

Resources