为什么不在Android工作室中显示Bangla字样?

时间:2017-03-01 06:42:19

标签: android

我想在Android应用中显示Bangla / Bengali的庄稼列表。我已经有一系列英文作物,如String[] crops={"paddy","potato","gourd"}; 在应用程序中显示相应的孟加拉名称,如果我只想显示“土豆”,应用程序将显示“আলু” 我按照此处显示的步骤操作:http://www.thedevline.com/2014/08/how-to-build-bangla-language-support.html

但它没有显示bangla虽然app运行。我在android studio工作。 有人可以帮忙吗? 我在databaseAccess.java文件中有以下函数 here

2 个答案:

答案 0 :(得分:0)

尝试使用自定义适配器为listview添加字体集

    public class MyArrayAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final String[] values;

    public MyArrayAdapter(Context context, String[] values) {
        super(context, R.layout.list_item, values);
        this.context = context;
        this.values = values;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.list_item, parent, false);

        TextView textView = (TextView) rowView.findViewById(R.id.label);

        //here use your true type font of Bangla like this bangla.ttf is placed inside asset/fonts/ folder of project
        Typeface face=Typeface.createFromAsset(getAssets(), "fonts/bangla.ttf"); 
        textView .setTypeface(face); 
        textView.setText(values[position]);
        return rowView;
    }
}

在您的活动中使用它,如:

 String[] names = new String[] { "আলু", "পেয়াজ", "বাদাম"};
 ListView myListView=(ListView)findViewById(android.R.id.list); //your listview
 myList.setAdapter(new MyArrayAdapter(this, names));    
res / layout中的

R.layout.list_item

    <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="5dp"
    android:singleLine="false"
    android:text="Text"
    android:textSize="15sp" />

答案 1 :(得分:0)

从`

下载库文件

https://github.com/androidbangladesh/BLS_SAMPLE_APP

并将其放入arrays文件夹。

现在在public string[][] userArray; public string[][] StudentArray; public int j; private void Start() { //First index length just an example userArray = new string[3][]; StudentArray = new string[userArray.Length][]; //These 2 declarations are just to let you see that the code can skip undeclared arrays userArray[0] = new string[6]; userArray[0][5] = "STUDENT"; userArray[2] = new string[8]; UserSorting(userArray); } public string[][] UserSorting(string[][] userArray) { j = 0; //for each row in user array for (int i = 0; i < userArray.Length; i++) { //Compares the stored account type to STUDENT if (userArray[i] != null) { if (userArray[i][5] == "STUDENT") { //for each user value copy into the new array StudentArray[j] = new string[userArray[i].Length]; for (int x = 0; x < userArray[i].Length; x++) { StudentArray[j][x] = userArray[i][x]; Debug.Log(StudentArray[j][x]); } //moves onto the next line ready for the next iteration j++; } } } return StudentArray; } 文件上添加

app\libs

有关更多信息,请访问: http://www.thedevline.com/2014/08/how-to-build-bangla-language-support.html