ARABIC-INDIC DIGIT android

2019-08-29 23:19发布

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?

enter image description here

标签: android digit
0条回答
登录 后发表回答