ARABIC-INDIC DIGIT android

≯℡__Kan透↙ 提交于 2019-12-12 01:54:46

问题


I am trying to show in my Android application the ARABIC-INDIC DIGIT.

So I tried this code, The method I used to display it is showed in the end of the class.

    public class num extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.num);


        Typeface Bader = Typeface.createFromAsset(getAssets(),"fonts/bader_al yadawi.ttf");

        final RelativeLayout rl = (RelativeLayout) findViewById(R.id.myLayout);
        Button back = (Button)findViewById(R.id.back);
        Button next = (Button)findViewById(R.id.next);
        Button previous = (Button)findViewById(R.id.previous);

        String Nm = toArabicDigits("1"); 
        String written = ArabicReshape.reshape("واحد");
        final TextView tv = (TextView)findViewById(R.id.tv);
        final TextView tv1 = (TextView)findViewById(R.id.tv1);
        tv.setTypeface(Bader);
        tv1.setTypeface(Bader);
        tv.setText(Nm);
        tv1.setText(written);

          back.setOnClickListener(new View.OnClickListener() {              
                @Override
                public void onClick(View view) {
                        Intent intent = new Intent(num.this, age1.class);
                        startActivity(intent);
                }
                   });

          next.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if(tv.getText().toString().equals(toArabicDigits("1"))){
                        String Nm = toArabicDigits("2"); 
                        String written = ArabicReshape.reshape("إثنان");
                        tv.setText(Nm);
                        tv1.setText(written);
                    }
                    else if(tv.getText().toString().equals(toArabicDigits("2"))){
                    String Nm = toArabicDigits("3"); 
                    String written = ArabicReshape.reshape("ثلاثة");
                    tv.setText(Nm);
                    tv1.setText(written);
                    }
                    else if(tv.getText().toString().equals(toArabicDigits("3"))){
                    String Nm = toArabicDigits("4"); 
                    String written = ArabicReshape.reshape("أربعة");
                    tv.setText(Nm);
                    tv1.setText(written);
                    }
                    }
            });

          previous.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {

                }
            });
    }

    private static String toArabicDigits(String eng) {

        char[] chars = {'٠','١','٢','٣','٤','٥','٦','٧','٨','٩'};
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < eng.length(); ++i) {
            if (Character.isDigit(eng.charAt(i))) {
                builder.append(chars[(int)(eng.charAt(i))-48]);
                System.out.println("char - " + eng.charAt(i) + " " + (int)(eng.charAt(i)-48) + " - " + chars[(int)(eng.charAt(i))-48]);
            } else {
                builder.append(eng.charAt(i));
            }
        }

        return builder.toString();
    }
}

But the application stops unexpectedly. Can anyone help me please?

来源:https://stackoverflow.com/questions/27795626/arabic-indic-digit-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!