2016-12-27 10 views
3

私は各項目にアラビア語のテキストで、アンドロイドで簡単なリストビューを作成しようとしています。問題は、表示されるテキストが完全に壊れており、アラビア語ではないことです。 AndroidスタジオのエンコーディングをUTF-8に設定しましたが、それは役に立たなかった。以下は Androidのアラビア語テキストListView

public class CategoryActivity extends AppCompatActivity { 

    // Array of strings... 
    String[] mobileArray = {"الرياضي","عربي وعالمي","الثقافي","دنيا","الامارات"}; 
    //String[] mobileArray ={"zaid", "ahmad", "abdallah"}; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_category); 

     ArrayAdapter adapter = new ArrayAdapter<String>(this, 
       R.layout.activity_listview, mobileArray); 

     ListView listView = (ListView) findViewById(R.id.mobile_list); 
     listView.setAdapter(adapter); 

    } 
} 
以下

私のxmlファイルがあり、

activity_category.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ListView 
     android:id="@+id/mobile_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 

</LinearLayout> 

activity_listvie私のアンドロイドのコードですw.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/label" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dip" 
    android:textSize="16dip" 
    android:textStyle="bold" 
    android:gravity="right"> 
</TextView> 

注:は、xmlファイルの作品に文字列配列をハードコーディングが、私はそれを望んでいません。私は実行時にデータベースから配列を取得したい。

+0

http://stackoverflow.com/questions/7962704/how-to-support-arabic-text-in-android?rq=1 –

+0

アラビア語のテキストをファイルから読み取ろうとしましたか? –

+0

いいえ、私はそれを試していませんでした。 –

答えて

1

に配列を<string-array>とします。

resvalues-arフォルダーにあるstring.xmlの中にアラビア語配列を配置します。

AndroidMenifest.xmlから"android:supportsRtl="true"<application>タグを使用してRTLを許可することができます。

+0

それは動作しますが、私は固定配列を持つことを望んでいません。ランタイムにデータベースから取得したい –

+0

あなたはアンドロイドのロケールを使用することができます。 詳細については、次のサイトのリンクをご覧ください。https://developer.android.com/reference/java/util/Locale.html – Naitik

関連する問題