I want to display image in TextView with text, I had used Html.ImageGetter but image was not displayed this is my code, please tell me what is wrong in this code
public class MyTest extends Activity {
TextView t=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t=(TextView)findViewById(R.id.textcode);
t.setText(Html.fromHtml("Hi", imgGetter, null));
}
private ImageGetter imgGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
Drawable drawable = null;
try {
drawable = getResources().getDrawable(R.drawable.icon);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable
.getIntrinsicHeight());
} catch (Exception e) {
e.printStackTrace();
Log.d("Exception thrown",e.getMessage());
}
return drawable;
}
};
}
ImageGetteris used for<img>tag parsing. So you have to have an<img>tag in your HTML code. For example,But you’d better make the
ImageGettersubclass return an image depending on thesourceargument.