android-SQLite代码段功能实现未在TextView中将文本格式设置为HTML

android-SQLite代码段功能实现未在TextView中将文本格式设置为HTML,第1张

概述我正在使用SQLite全文搜索实现搜索功能.我想像Google搜索一样用粗体查询文本显示结果!我已经实现了类似下面的代码,但是它通过将视图绑定到光标适配器并设置TextView的文本格式来显示纯文本,而没有任何HTML格式.我无法弄清楚代码中的错误之处?任何帮助请!我在DatabaseAdapter类中的搜

我正在使用sqlite全文搜索实现搜索功能.我想像Google搜索一样用粗体查询文本显示结果!我已经实现了类似下面的代码,但是它通过将视图绑定到光标适配器并设置TextVIEw的文本格式来显示纯文本,而没有任何HTML格式.我无法弄清楚代码中的错误之处?任何帮助请!

我在DatabaseAdapter类中的搜索功能是:

public Cursor searchText(String inputText) throws sqlException {    Log.w(TAG, inputText);    String query = "SELECT "+    "docID as _ID," +     KEY_name + "," +    KEY_INDEX + "," +    KEY_TEXT_en + "," +    KEY_TEXT_ur +  "," +    KEY_TRANS_ur +  "," +    "hex(matchinfo("+FTS_VIRTUAL_table+")) AS "+KEY_OCCURRENCES+"," +    "snippet("+FTS_VIRTUAL_table+",'<b>','</b>')" +    " from " + FTS_VIRTUAL_table +    " where ("+  FTS_VIRTUAL_table +") MATCH '" + "\""+"*"+inputText+"\"*"+" ';";    Log.w(TAG, query);    Cursor mCursor = mDb.rawquery(query,null);    if (mCursor != null)     {        mCursor.movetoFirst();    }    return mCursor;}

在活动类中向用户显示结果的show Results函数是:

public voID showResults(String query) {    Cursor cursor = mDbHelper.searchText((query != null ? query.toString() : "@@@@"));    if (cursor == null)    {    }    else     {        // Specify the columns we want to display in the result        String[] from = new String[]                 {                    DbAdapter.KEY_TEXT_en,                    DbAdapter.KEY_INDEX,                    DbAdapter.KEY_name,                };           // Specify the Corresponding layout elements where we want the columns to go        int[] to = new int[]                 {                    R.ID.TextEnTv,                    R.ID.IndexTv,                    R.ID.nameTv                }; final SimpleCursorAdapter cursorAdapter = new simpleCursorAdapter(this,R.layout.search_results, cursor, from, to);        cursorAdapter.setVIEwBinder(new SimpleCursorAdapter.VIEwBinder() {            public boolean setVIEwValue(VIEw vIEw,Cursor cursor, int columnIndex) {                   if (columnIndex == cursor.getColumnIndex(DbAdapter.KEY_TEXT_en)) {                        TextVIEw myVIEw = (TextVIEw) findVIEwByID(R.ID.TextEnTv);                        myVIEw.setText(HTML.fromHTML(cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_TEXT_en))));                        return(true);                      }                      return(false);                    }                  });        mListVIEw.setAdapter(cursorAdapter);

解决方法:

文本视图显示未格式化的文本,因为代码告诉它显示KEY_TEXT_en列的内容,即未格式化的文本.

要显示摘录功能的结果,请为其命名:

SELECT ... snippet(...) AS snippet ...

并将该列用于文本视图.

总结

以上是内存溢出为你收集整理的android-SQLite代码段功能实现未在TextView中将文本格式设置为HTML全部内容,希望文章能够帮你解决android-SQLite代码段功能实现未在TextView中将文本格式设置为HTML所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1093674.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存