我是一名新的Android开发人员。我在我的应用程序中使用拉丁字体,但我无法让它工作并继续获得该字符的?
。我的代码如下,使用sqlite数据库。我必须从Sqlite数据库中获取文本,并且每个特殊的拉丁字符(即à,ò,ù,è...)都显示为带有“?”的黑色方块。内部。
如何才能正确显示?
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);
}
我的模拟器屏幕:
我也试过这段代码:
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);
}
但是这给了我以下错误:
Typeface类型中的createFromAsset(AssetManager,String)方法不适用于参数(String,String)。
我使用的是Sqlitehelper类,我的代码如下:
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.close();
return cur;
}
public Cursor getAnswerFifthDeclensionNounsQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM FifthDeclensionNounsQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnswerNounsAllDeclensionNounsQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM NounsDeclensionNounsQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnsweris_ea_idQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM IsEaIdQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnswerhic_haec_hocQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM HicHaecHocQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnswerille_illa_illudQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM IlleIllaIlludQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnswerqui_quae_quodQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM QuiQuaeQuodQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnswerIdem_eadem_idemQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM IdemEademIdemQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnsweripse_ipsa_ipsumQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM IpseIpsaIpsumQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnsweralius_alia_aliudQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM AliusAliaAliudQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
public Cursor getAnswerAdjectiveQuestions(String question) {
Cursor cur;
cur = vocabDatabase.rawQuery(
"SELECT * FROM AdjectivesQuestions WHERE Question LIKE '"
+ question + "'", null);
cur.moveToFirst();
vocabDatabase.close();
return cur;
}
@Override
public synchronized void close() {
if (vocabDatabase != null)
vocabDatabase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
答案 0 :(得分:1)
我的猜测是,在“bon?”中代替“?”的字符是“ō”U + 014D带有MACRON的小写字母O,因为这确实是唯一明智的可能性。拉丁语仅使用普通的A到Z字母编写,但是macron通常用在字典和语法中的元音上方,表示元音发音很长。
字符“ō”在实际的Android设备上显示OK,但您的模拟器可能存在字体问题(即,它使用的字体不包含该字符)。更可能的是,存在字符编码问题。如果没有进一步的信息(例如,使用哪个模拟器,如何在HTML中表示字符,以及如何声明HTML文档的编码以及实际编码是什么),很难分析它。
答案 1 :(得分:1)
我不知道你在代码中做了些什么以及为什么使用HTML?但我可以假设你需要这个简单的代码。请参阅以下修改方法。
private void displayTestQuestion() {
resetEverything();
stats.setText(Integer.toString(totalRightQuestions)+"/"+Integer.toString(totalNumberOfQuestions));
String questionText = questionCursor.getString(0);
Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fonts/LATINWD.TTF");
question.setTypeface(font);
question.setText(questionText);
adjectiveNumber = questionCursor.getString(1);
adjectiveCase = questionCursor.getString(3);
adjectiveGender = questionCursor.getString(2);
}