我正在开发一个伊斯兰应用程序。我从 Sq-lite 数据库获得一个阿拉伯语字符串,但当我尝试显示此字符串时,无法正确显示。我还设置了Java页面的编码UTF-8。但是当我直接使用此字符串时,它会以正确的样式显示。我也在使用字体,但不能解决我的问题有人可以帮忙吗?告诉我一些解决方案来解决这个问题。我的代码在这里..
String arabic ="ذَلِكَ الْكِتَابُ لَا رَيْبَ فِيهِ هُدًى لِلْمُتَّقِينَ";
当我使用它时,它可以工作。但是当我使用SQLite数据库中的字符串时,它没有显示正确。
public class MainActivity extends Activity {
//Variables.....
TextView arabicTV,urduTV;
TableLayout tablelayout;
TableRow tableRow;
Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tablelayout = (TableLayout)findViewById(R.id.tablelayout);
Typeface arabicFont = Typeface.createFromAsset(getAssets(), "Al Qalam Quran Publisher.ttf");
DBAdapter db = new DBAdapter(this);
Cursor c =db.getAllAyyat();
if(c.moveToFirst()){
do{
String value = c.getString(0);
System.out.println(value);
tableRow = new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(450, TableRow.LayoutParams.WRAP_CONTENT);
tableRow.setLayoutParams(lp);
lp.setMargins(4, 3, 6, 8);
arabicTV = new TextView(this);
arabicTV.setLayoutParams(lp);
arabicTV.setText(value);
arabicTV.setTypeface(arabicFont);
arabicTV.setBackgroundColor(Color.CYAN);
arabicTV.setPadding(3, 3, 3, 3);
arabicTV.setTextColor(Color.BLACK);
arabicTV.setTextSize(40);
tableRow.addView(arabicTV);
tablelayout.addView(tableRow);
}while(c.moveToNext());
}
}
它与 UTF-8 或字体类型无关,,, 我的应用程序中有 7 种顺从语言,android 系统可以清楚地显示它们。
让光标查询数据库,然后使用 c.getString(0);这里有一个例子:从 SQLite 检索单个数据并在 TextView 中显示(Android 开发)
如果它仍然对你不起作用,,,我很乐意尽可能地提供帮助,,, jouid33@gmail.com