2017-03-01 61 views
0

我想在android應用程序中顯示Bangla/Bengali中的作物列表。我已經有作物的數組中英文像String[] crops={"paddy","potato","gourd"}; 顯示應用相應孟加拉的名字一樣,如果我想只顯示「土豆」,應用程序會顯示「আলু」 我跟着此處顯示的步驟:http://www.thedevline.com/2014/08/how-to-build-bangla-language-support.html爲什麼不在Android Studio中顯示Bangla單詞?

但它沒有顯示孟加拉,但應用程序運行。我在android studio工作。 任何人都可以請幫忙嗎? 我在databaseAccess.java文件下列功能與您的字體設置

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; 
    } 
} 

在活動中使用它像 here

+0

發佈您的代碼.. – rafsanahmad007

+0

你嘗試過什麼到目前爲止?有什麼例外?錯誤? –

+0

我試圖按照鏈接http://www.thedevline.com/2014/08/how-to-build-bangla-language-support.html中的步驟運行給定的代碼。雖然應用程序運行但不顯示文本。它是空白的 – suptagni

回答

0

嘗試使用自定義的適配器列表視圖:

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" /> 
+0

好的。我正在嘗試@ rafsanahmad007 – suptagni

+0

WoW!有用 !非常感謝@ rafsanahmad007 – suptagni

+0

myListView的類型是什麼?在我的活動下是xml文件中的listView類型@ rafsanahmad007 – suptagni

相關問題