Android,显示没有HTML标签的数据

时间:2013-04-06 12:19:12

标签: android html sqlite

我有sqlite表,其中包含HTML标记的记录。我想以正确的格式在我的应用程序中显示它们,这样用户只能看到实际结果而不是标签。有谁知道怎么做?

这是我使用的代码,也是单个记录的示例:

代码:

try {

        Cursor cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM definition WHERE data_id='"+word[0].toLowerCase().trim()+"'", null);

        //Cursor cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT catgram FROM adresse_definition WHERE index_nom_adresse=word[0].toLowerCase().trim()", null);

        //Cursor cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT catgram FROM adresse_definition JOIN definition ON adresse_definition.definition = definition.data_id WHERE index_nom_adresse='" + word[0].toLowerCase().trim()+"'", null);
        //Cursor cursor = dictionary.getDictionaryDatabase().query("adresse_definition", null, "index_nom_adresse= '" + word[0].toLowerCase().trim() + "' or definition= '" + word[0].toUpperCase().trim() + "' ", null, null, null, null);
        cursor.moveToFirst();
        if (cursor.getCount() != 0) {

            if (word[1] == null || word[1].equals("English")) {
                translatedWord = cursor.getString(2);
            } else {
                translatedWord = cursor.getString(1);
            }
        } else {
            translatedWord = "The word is not in database";
        }
        cursor.close();
    } catch (SQLiteException sqle) {
        translatedWord = "The word is not in database";
    }

    dictionary.close();

记录:

<div class="art"><br /><a class="Ls" href="01682"> </a> <h1 class="Ad">bonjour </h1><span class="Ph"> [bɔ̃ʒur]</span><br /><span class="Cg"> nom masculin</span><table border="0"><tr><td align="left" valign="top" class="N"><span class="Cg">1.</span></td><td align="left" valign="top" class="Cg"> <span class="In"> [salutation - généralement]</span><a class="Ls2" href="30793ang2">&nbsp;</a><span class="Tr"> hello</span><br /><span class="In">[ - le matin]</span><a class="Ls2" href="3443ang2">&nbsp;</a><span class="Tr"> good morning</span><br /><span class="In">[ - l'après-midi]</span><a class="Ls2" href="3440ang2">&nbsp;</a><span class="Tr"> good afternoon</span><br /> <a class="Ls3" href="221818fra2">&nbsp;</a><span class="L2" id="816343">vous lui donnerez le bonjour <small class="Ob">ou</small> vous lui direz bonjour de ma part</span><a class="Ls2" href="159366ang2">&nbsp;</a><span class="Tr2"> say hello for me</span><br /> <a class="Ls3" href="221819fra2">&nbsp;</a><span class="L2" id="816344">vous avez le bonjour de Martin</span><a class="Ls2" href="159367ang2">&nbsp;</a><span class="Tr2"> Martin sends his love</span><br /> <a class="Ls3" href="221820fra2">&nbsp;</a><span class="L2" id="816345">bien le bonjour chez vous</span><a class="Ls2" href="159368ang2">&nbsp;</a><span class="Tr2"> regards to everybody (back home)</span></td></tr></table><table border="0"><tr><td align="left" valign="top" class="N"><span class="Cg">2.</span></td><td align="left" valign="top" class="Cg"> <span class="Mt"> (familier) </span><span class="In"> [exprime la difficulté]</span><br /> <a class="Ls3" href="221821fra2">&nbsp;</a><span class="L2" id="816346">pour le faire aller à l'école, bonjour!</span><a class="Ls2" href="159369ang2">&nbsp;</a><span class="Tr2"> no way can you get him to go to school!</span><br /> <a class="Ls3" href="221822fra2">&nbsp;</a><span class="L2" id="816347">je n'ai pas fait de gym depuis un mois, bonjour les courbatures!</span><a class="Ls2" href="159370ang2">&nbsp;</a><span class="Tr2"> I haven't done any exercise for a month, I'm going to ache, let me tell you!</span></td></tr></table><br /><br /></div>

1 个答案:

答案 0 :(得分:1)

这可能会帮助您,如果您从Result得到正确的Sqlite,那么您可以显示数据,确保回复正确。

TextView  txtweb = (TextView) findViewById(R.id.txtweb);
txtweb.setText(Html.fromHtml(mresult));