1

first of all wish you

Very Happy New Year.

Now come to the point. Here i want to show text with icon. I am only able to show the text but not the icon.How can i do this?

one important thing i am Getting response from server. Images can be changed. Whole thing is coming in shot.Not line by line

Below is the sample :

enter image description here

Any kind of help will be extremely appreciated.

Updated:

Response from server:

<div class=\"specsSection\">\n<p><strong>Entertainment on the Go</strong></p>\n
<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" class=\"tblSpecs\"><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/dolbyplus.jpg\" />
</td>\n<td>Sharp and Natural Sound with Digital Dolby Plus</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/wifi.jpg\" /></td>\n<td>
GPRS + WiFi (With Voice Calling)</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/lcd.jpg\" /></td>\n
<td>7\"Capacitive Touch LCD</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/dualcore.jpg\" /></td>\n
<td>Dual Core Processor</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/storage.jpg\" /></td>\n
<td>1 GB RAM, 4 GB eMMC</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/android.jpg\" /></td>\n
<td>Andorid 4.2 JellyBean</td>\n</tr><tr><td>
<img src=\"http://xyz.abc.in/sites/xyz.abc.in/icons/battery.jpg\" /></td>\n
<td>7+ hours of battery life</td>\n</tr></table></div>\n<div style=\"clear:both\">      </div>\n",
Community
  • 1
  • 1
rupesh
  • 2,865
  • 4
  • 24
  • 50

2 Answers2

3

use android:drawableLeft="" attribute for TextView

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/image1" />

and if you want to give the space between image and text use,

 android:drawablePadding="" attribute...

and to set images dynamically, use

textView.setCompoundDrawablesWithIntrinsicBounds();

so you are getting image Urls from Server. see the thread here how to download images from Server. get the Stream from Connection and decode it using BitmapFactory.decodeStream().

    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
    BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
    textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);

use AsyncTask to download the image and get the Bitmap, set to TextView in UI thread...

Community
  • 1
  • 1
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
  • please check the updated question.Here some confusion has got created. – rupesh Jan 01 '14 at 12:35
  • But response is in HTML tag so again how can i get the images and text separately. as you can see the above, i have posted my response. – rupesh Jan 01 '14 at 12:48
  • again My question is how i filter the image tag and text separtely while i am getting this in Single string.@Gopal rao – rupesh Jan 01 '14 at 12:58
  • @rup35h see the thread here http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 and here http://stackoverflow.com/questions/8480130/parsing-html-in-java-for-an-android-app and here http://stackoverflow.com/questions/6998163/android-java-get-html-image-tag-from-string and here http://stackoverflow.com/questions/11010171/parsing-an-image-url-from-an-html-file and see some sample code here https://gist.github.com/Antarix/4167655 – Gopal Gopi Jan 01 '14 at 13:01
0

You can use android:drawableLeft="@drawable/image_at_left" in order to assign image exactly at the left of the TextView

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/image_at_left"
    android:text="TextView" />

OR

You can set the drawables programmatically..

setCompoundDrawablesWithIntrinsicBounds();

Android Doc

Jagadesh Seeram
  • 2,630
  • 1
  • 16
  • 29