suptagni
suptagni

Reputation: 61

Why not showing Bangla words in Android studio?

I am trying to show a list of crops in Bangla/Bengali in the android app. I already have an array of crops in english like String[] crops={"paddy","potato","gourd"}; showing corresponding bangla name in app like if I want to show only "potato",the app will show "আলু" I followed the steps shown here: http://www.thedevline.com/2014/08/how-to-build-bangla-language-support.html

But it did not show bangla though app was run. I am working in android studio. Can anyone please help ? I have following function in databaseAccess.java file here

Upvotes: 1

Views: 1933

Answers (2)

Juboraj Sarker
Juboraj Sarker

Reputation: 957

Download library file from`

https://github.com/androidbangladesh/BLS_SAMPLE_APP

and place it to app\libsfolder.

Now on build.gradlefile simply add

 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/bls-1.0.jar')
} 

For more information you may visit: http://www.thedevline.com/2014/08/how-to-build-bangla-language-support.html

Upvotes: 0

rafsanahmad007
rafsanahmad007

Reputation: 23881

try using a custom adapter for listview with your font set

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

use it in your Activity like:

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

in 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" />

Upvotes: 1

Related Questions