次のような文字列があります。
String text = "<img src="https://www.google.com/images/srpr/logo3w.png">"
私がする時
TextView.setText(Html.fromHtml(text));
アクティビティに画像を表示する必要があります。
WebView を使用したくありません。
これを達成するための他の方法について教えてください。
次のような文字列があります。
String text = "<img src="https://www.google.com/images/srpr/logo3w.png">"
私がする時
TextView.setText(Html.fromHtml(text));
アクティビティに画像を表示する必要があります。
WebView を使用したくありません。
これを達成するための他の方法について教えてください。
asynctaskを使用する必要があり、doInbackground()
画像をテキストビューに設定して接続を開きます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);
}
それが役立つことを願っています。
以下のリンクのアイデアに従いました。
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
テキストを定義する必要がありますstrings.xml
<string name="nice_html">
<![CDATA[<img src='https://www.google.com/images/srpr/logo3w.png'>
]]></string>
次に、コードで:
TextView foo = (TextView)findViewById(R.id.foo);
foo.setText(Html.fromHtml(getString(R.string.nice_html)));