如何从服务器收到的html文本中显示TextView中的ImageSpan?

时间:2013-05-03 08:24:36

标签: android image textview

这是我的问题:

首先,我将一个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);

但是,我能看到的只是一个图像方块: enter image description here

1 个答案:

答案 0 :(得分:1)