0
這裏是我的問題:如何使用從服務器收到的HTML文本在TextView中顯示ImageSpan?
起初,我送一個HTML的文本到服務器:
Uri img_uri = Uri.parse("android.resource://mypackage/" + R.drawable.emotion_smile);
ImageSpan imageSpan = new ImageSpan(editor_activity, img_uri);
int insert_loc = mEditorBody.getSelectionStart();
span_builder.insert(insert_loc, "`a`");
span_builder.setSpan(imageSpan, insert_loc, insert_loc+3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mEditorBody.setText(span_builder);
mEditorBody.setSelection(insert_loc+1);
HttpClient client = new DefaultHttpClient();
HttpPost post_req = new HttpPost(SERVER);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
text_body = mEditorBody.getText();
nameValuePairs.add(new BasicNameValuePair("content", Html.toHtml(text_body)));
try {
post_req.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
response = client.execute(post_req);
}
我發送的HTML文本是:
<p dir="ltr">1234567123<img src="android.resource://com.mydev.mypackage/2130837510">1238912<img src="android.resource://com.mydev.mypackage/2130837510"></p>
,然後我試着以恢復列表視圖中的消息:
viewgroup.textview1.setText(Html.fromHtml(item_list.get(position)), TextView.BufferType.SPANNABLE);
但是,我所看到的只是一個像方:其他
很好,似乎沒有人能解決我的問題。我必須採取一些小技巧解決方案:將文本保存爲html,然後將其保存爲純文本,並將情感替換爲一些不常見的字符,如「\'a \'」。從服務器獲取後,我再次用ImageSpan替換「\'a \'」 – Flybywind 2013-05-06 07:42:29