skip to Main Content

I have downloaded a word meaning Android sqlite.db dictionary file. By fetching SQL query I got

enslishWord="plausible";
hindiMeaning="lR;kHkklh]diViw.kZ]";

By using Hindi Typeface in TextView I got proper Hindi meaning. If I try to print by System.out.println(hindiMeaning); it prints lR;kHkklh]diViw.kZ]

I am confused about the problem and looking for a solution. Please, check the raw Android sqlite.db Github link in comment sections.

2

Answers


  1. add this class

    public class typeface extends TypefaceSpan {
        Typeface typeface;
    
        public typeface(String family, Typeface typeface) {
            super(family);
            this.typeface = typeface;
        }
    
        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setTypeface(typeface);
        }
    
        @Override
        public void updateMeasureState(TextPaint ds) {
            ds.setTypeface(typeface);
        }
    
    }`
    

    Add this method to you activity

     public SpannableString spannableString(String string, String your_working_hindi_font_name , Context context) {
    
        SpannableString span = new SpannableString(string);
        span.setSpan(new typeface("", Typeface.createFromAsset(context.getAssets(),
                "" + your_working_hindi_font_name + ".ttf")), 0, span.length(), span.SPAN_EXCLUSIVE_EXCLUSIVE);
    
        return span;
    
    }
    public void spannableToast(SpannableString text, Context context) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }
    

    call method
    to show toast

    spannableToast(spannableString(normal, "hindi" , getContext()) , getContext());
    

    to set text

     phoneTv.setText( spannableString(normal, "hindi" , getContext()));
    
    Login or Signup to reply.
  2. If I try to print by System.out.println(hindiMeaning); it prints lR;kHkklh]diViw.kZ].

    Are you trying to print the non-English characters in Console?

    android.graphics.Typeface is an Android-specific class whereas System.out.println is a Java-specific function. You can’t expect the Java console to print out the non-English characters by default.

    In Android Studio the default encoding can be set in the studio64.exe.vmoptions file as an ordinary VM parameter. This file is located inside the root folder of your Android Studio installation and contains a set of JVM parameters. Add -Dfile.encoding=UTF-8 there to set encoding in UTF-8.

    Alternatively, you can change the option via the settings.

    Reference: IntelliJ IDEA incorrect encoding in console output

    Android Studio Settings

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search