Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

sqlite - How can I display Latin words in Android?

I am a new Android developer. I'm working with a Latin font in my app but I can't get it to work and keep getting a ? for the character. My code is below, using an sqlite database.I have to fetch text from an Sqlite database and every special Latin character (i.e. à, ò, ù, è...) was displayed with black squares with a "?" inside.

How can i display this correctly?

private void displayTestQuestion() {
    resetEverything();
    stats.setText(Integer.toString(totalRightQuestions)+"/"+Integer.toString(totalNumberOfQuestions));

    String questionText = questionCursor.getString(0);
    question.setText(Html.fromHtml(questionText));
    adjectiveNumber = questionCursor.getString(1);
    adjectiveCase = questionCursor.getString(3);
    adjectiveGender = questionCursor.getString(2);
}

My emulator screen:

enter image description here

I've also tried this code:

private void displayTestQuestion() {
    resetEverything();
    stats.setText(Integer.toString(totalRightQuestions)+"/"+Integer.toString(totalNumberOfQuestions));

    String questionText = questionCursor.getString(0);
    Typeface font = Typeface.createFromAsset(questionCursor.getString(0), "fonts/LATINWD.TTF");
    //question.setText(Html.fromHtml(questionText));
    question.setText((CharSequence) font);
    adjectiveNumber = questionCursor.getString(1);
    adjectiveCase = questionCursor.getString(3);
    adjectiveGender = questionCursor.getString(2);
}

But this is giving me the following error:

The method createFromAsset(AssetManager, String) in the type Typeface is not applicable for the arguments (String, String).

And i used Sqlitehelper class my code is below:

public class VocabTesterDatabaseHelper extends SQLiteOpenHelper {

    private static String DB_PATH = "data/data/com.VoacabTester/databases/";

    private static String DB_NAME = "vocabdb.db";

    private SQLiteDatabase vocabDatabase;

    private final Context vocabContext;

    public VocabTesterDatabaseHelper(Context context) {
        super(context, DB_NAME, null, 3);
        this.vocabContext = context;
    }

    public void createDataBase() throws IOException {

        boolean dbExist = checkDataBase();

        if (dbExist) {

        } else {
            this.getReadableDatabase();
            copyDataBase();
        }

    }

    private boolean checkDataBase() {

        File dbFile = new File(DB_PATH + DB_NAME);
        return dbFile.exists();
    }

    private void copyDataBase() throws IOException {
        try {

            InputStream myInput = vocabContext.getAssets().open(DB_NAME);
            String outFileName = DB_PATH + DB_NAME;

            // Open the empty db as the output stream
            OutputStream myOutput = new FileOutputStream(outFileName);

            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }
            myOutput.flush();
            myOutput.close();
            myInput.close();
        } catch (IOException e) {
            Log.v("data", e.toString().concat("sql"));
        }
    }

    public void openDataBase() throws SQLException {

        // Open the database
        String myPath = DB_PATH + DB_NAME;
        vocabDatabase = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READONLY);

    }

    public Cursor getFoundationTierQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM FoundationTierVocabularyQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    };

    public Cursor getHigherTierQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM HigherTierQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getEasyFirstConjugationVerbs() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM VerbQuestions1stConjugation ORDER BY Random()",
                null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getEasySecondConjugationVerbs() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM VerbQuestions2ndConjugation ORDER BY Random()",
                null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getEasyThirdConjugationVerbs() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM VerbQuestions3rdConjugation ORDER BY Random()",
                null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getEasyFourthConjugationVerbs() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM VerbQuestions4thConjugation ORDER BY Random()",
                null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getEasyMixConjugationVerbs() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM VerbQuestionsallConjugation ORDER BY Random()",
                null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getEasyIrregularConjugationVerbs() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM IrregularVerbsQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getFirstDeclensionNounsQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM FirstDeclensionNounsQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getSecondDeclensionNounsQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM SecondDeclensionNounsQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getThirdDeclensionNounsQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM ThirdDeclensionNounsQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getFourthDeclensionNounsQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM FourthDeclensionNounsQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getFifthDeclensionNounsQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM FifthDeclensionNounsQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getNounsAllDeclensionNounsQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM NounsDeclensionNounsQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getis_ea_idQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM IsEaIdQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor gethic_haec_hocQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM HicHaecHocQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getille_illa_illudQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM IlleIllaIlludQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getqui_quae_quodQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM QuiQuaeQuodQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getIdem_eadem_idemQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM IdemEademIdemQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getipse_ipsa_ipsumQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM IpseIpsaIpsumQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getalius_alia_aliudQuestions() {
        Cursor cur;
        cur = vocabDatabase
                .rawQuery(
                        "SELECT * FROM AliusAliaAliudQuestions ORDER BY Random()",
                        null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getAdjectiveQuestions() {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM AdjectivesQuestions ORDER BY Random()", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getAnswerFirstDeclensionNounsQuestion(String question) {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM FirstDeclensionNounsQuestions WHERE Question LIKE '"
                        + question + "'", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getSAnswerecondDeclensionNounsQuestions(String question) {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM SecondDeclensionNounsQuestions WHERE Question LIKE '"
                        + question + "'", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getAnswerThirdDeclensionNounsQuestions(String question) {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM ThirdDeclensionNounsQuestions WHERE Question LIKE '"
                        + question + "'", null);
        cur.moveToFirst();
        vocabDatabase.close();
        return cur;
    }

    public Cursor getAnswerFourthDeclensionNounsQuestions(String question) {
        Cursor cur;
        cur = vocabDatabase.rawQuery(
                "SELECT * FROM FourthDeclensionNounsQuestions WHERE Question LIKE '"
                        + question + "'", null);
        cur.moveToFirst();
        vocabDatabase.c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

My guess is that the character in place of “?” in “bon?” is “ō” U+014D LATIN SMALL LETTER O WITH MACRON, because that’s really the only sensible possibility. Latin as such is written using plain A to Z letters only, but the macron is often used above vowels in dictionaries and grammars to indicate that a vowel is pronounced long.

The character “ō” displays OK on an actual Android device, but your emulator might have a font problem with it (i.e., the font it is using does not contain the character). More probably, there is a character encoding problem. It can hardly be analyzed without further information (e.g., which emulator is used, how the character is represented in HTML, and how the encoding of the HTML document has been declared, and what the actual encoding is).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...