I wish to show Images in TextView. My Images are saved in res/raw directory. I tried using HTML.ImageGetter but could not find a complete reference for same.
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.widget.TextView;
public class TextImageActivity extends Activity {
int imageNumber = 1; //int to check which image is displayed
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tvText = (TextView) findViewById(R.id.text);
final String testContent = "TestItalic
"
+ "This is like testing if this thing works" + "" +
" in a more elaborate";
tvText.setText(Html.fromHtml(testContent, imgGetter, null));
}
private ImageGetter imgGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
Drawable drawable = null;
if(imageNumber == 1) {
drawable = getResources().getDrawable(R.raw.icon);
++imageNumber;
} else drawable = getResources().getDrawable(R.raw.a);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable
.getIntrinsicHeight());
return drawable;
}
};
}