Reputation: 1561
I have a string which as follows:
String text = "<img src="https://www.google.com/images/srpr/logo3w.png">"
When I do
TextView.setText(Html.fromHtml(text));
I need the image to be displayed in the activity.
I do not want to use a WebView.
Please let me know as to what are the other ways to achieve this.
Upvotes: 2
Views: 1657
Reputation: 1561
I followed the idea in these below links.
http://www.docstoc.com/docs/120417139/How-To-Implement-Htmlfromhtml-With-Imagegetter-In-Android
http://shiamiprogrammingnotes.blogspot.com/2010/09/textview-with-html-content-with-images.html
Upvotes: 1
Reputation: 4132
You need to define your text in strings.xml
<string name="nice_html">
<![CDATA[<img src='https://www.google.com/images/srpr/logo3w.png'>
]]></string>
Then, in your code:
TextView foo = (TextView)findViewById(R.id.foo);
foo.setText(Html.fromHtml(getString(R.string.nice_html)));
Upvotes: 0
Reputation: 10959
you have to use asynctask,open connection in doInbackground()
set image to textview in onPostExecute()
try {
/* Open a new URL and get the InputStream to load data from it. */
URL aURL = new URL("ur Image URL");
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(is);
/* Decode url-data to a bitmap. */
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
Drawable d =new BitmapDrawable(bm);
d.setId("1");
textview.setCompoundDrawablesWithIntrinsicBounds(0,0,1,0);// wherever u want the image relative to textview
} catch (IOException e) {
Log.e("error", "Remote Image Exception", e);
}
Hope it will help.
Upvotes: 1