【发布时间】:2018-12-07 15:10:07
【问题描述】:
我遇到的问题是,使用 StrikethroughSpan 时,删除线文本没有保存到我的应用程序的 SQLite 数据库中。但它适用于其他跨度,特别是 StyleSpan 和 UnderlineSpan - 粗体/斜体/下划线文本正确保存到数据库并由 CursorAdapter 显示。我为此目的使用 HtmlCompat。但是删除线显示为没有格式的纯文本。
我对此事的网络研究没有给出任何结果。这种行为的原因是什么,有没有办法解决这个问题?
我将跨区文本保存到数据库的代码:
ContentValues values = new ContentValues();
NoteCursorAdapter cursorAdapter = new NoteCursorAdapter(this, null);
String newHtmlString = HtmlCompat.toHtml(noteText, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
values.put(NoteEntry.COLUMN_NOTE_TEXT, newHtmlString);
活动中:
@Override
public void bindView(View view, Context context, Cursor cursor) {
...
String htmlFormString = cursor.getString(noteBitmapColumnIndex);
Spanned spannedText = HtmlCompat.fromHtml(htmlFormString, FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE);
noteBitmap.setText(spannedText);
}
在 CursorAdapter 中:
@Override
public void onLoadFinished(...) {
...
htmlString = cursor.getString(textColumnIndex);
realText = HtmlCompat.fromHtml(htmlFormString, FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE);
mNoteText.setText(realText);
放入 ContentValues (newHtmlString) 的 html 字符串显示相应的 HTML 标签:
I/System.out: <p dir="ltr"><b><b><strike>Word</strike></b></b></p>
但格式不显示。
【问题讨论】:
-
您如何存储数据?从数据库中读取的 html 字符串是什么样的?
-
请看我的更新。我使用 DBHelper/ContentProvider 存储数据并通过 HtmlCompat.toHtml 转换文本。放在 ContentValues (newHtmlString) 中的 html 字符串显示标签
、: I/System.out:Word
标签: android html sqlite save strikethrough