android - 从 sqlite 中获取的阿拉伯字符串在 android 中显示不正确?

标签 android string sqlite arabic

我正在开发一款伊斯兰应用程序。 我正在从 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);这里有一个例子:Retrieving single data from SQLite and display in TextView (Android Development)

如果它仍然对您不起作用,,, 我非常乐意尽可能提供帮助,,, jouid33@gmail.com

关于android - 从 sqlite 中获取的阿拉伯字符串在 android 中显示不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20655475/

相关文章:

c - 分析字符串的一部分

android - 无法使用 sqlite 查询获取过去两个月的数据

python - 如何连接 3 个表并执行 func.sum

Android 运行时错误与发布版本但不是调试版本

java - 音频暂停时暂停变化的图像

string - lua中查找字符串中的数字

c# - string.Replace 或 stringBuilder.Replace()

java - 从数据库崩溃中检索数据

android - Xamarin.Android : How to stop Visual Studio from removing the previous version of the app before deploying

android - 运行 Android Studio 时出错