سؤال

أقوم بعمل تطبيق مع النص والبيانات اليونانية ولكن لا يتم عرض كل حرف. رسالة لا تظهر ? مارك ولكن مجرد مساحة بيضاء. تم تعيين ترميز الملفات على utf8 و في build.gradle, ، لقد قمت بتعيين ترجمة ل utf8.

فمثلا: (agapó) ἀγαπῶ (ἀγαπᾶν) في ListView يظهر على أنه (agapó) γαπ (γαπ ν). حتى زر على XML لا يظهر نفس المشكلة بشكل صحيح.

لقطة الشاشة:

enter image description here

  private void inicialization() {

    sound = (ImageView) findViewById(R.id.sound);
    home = (ImageView) findViewById(R.id.home);
    home.setOnClickListener(this);

    setData();

    listwords = (ListView) findViewById(R.id.listwords);
    adapter = new ArrayAdapter<String>(this, R.layout.adapteritem, R.id.greek_word, Timeslist);
    listwords.setAdapter(adapter);
    listwords.setOnItemClickListener(this);

    play = (Button) findViewById(R.id.play);
    stop = (Button) findViewById(R.id.stop);
    play.setOnClickListener(this);
    stop.setOnClickListener(this);

    tv1 = (TextView)findViewById(R.id.text1);
    tv2 = (TextView)findViewById(R.id.text2);
    tv3 = (TextView)findViewById(R.id.text3);
    tv4 = (TextView)findViewById(R.id.text4);
    tv5 = (TextView)findViewById(R.id.text5);

    setPlayer();
}

private void setData() {

    int index;
    index = getIntent().getIntExtra("index", 0);

    switch (index){
        case 0:
            if(lang){
                Timeslist = GlobalTimes.Times1ListCZ; // from global class of arrays
                TimesAudio = GlobalTimes.Times1AudioCZ;
                TimesWords = GlobalTimes.Times1WordsCZ;
            }
            if(!lang){
                Timeslist =  GlobalTimes.Times1List;
                TimesAudio = GlobalTimes.Times1Audio;
                TimesWords = GlobalTimes.Times1Words;
            }
            break;
    }
}

والبيانات من GlobalClass

public class GlobalTimes {

public static String[] Times1List = { "(agapó) ἀγαπῶ (ἀγαπᾶν)", "(agó) ἄγω", "(airó) αἴρω", "(akúó) ἀκούω", "(hamartanó) ἁμαρτάνω", "(anabainó) ἀναβαίνω"};
public static Integer[] Times1Audio = { R.raw.miluji, R.raw.vedu, R.raw.zdviham, R.raw.slysim, R.raw.hresim, R.raw.jdunahoru };
public static String[][] Times1Words = {

        {
                "ἀγαπῶ",     
                "ἀγαπᾶν",    
                "ἀγαπήσω",   
                "ἠγάπησα",  
                "ἠγάπηκα",   
                "ἠγάπημαι",  
                "ἠγαπήθην", 
                "miluji"
        },
        {
                "ἄγω",
                "x",
                "ἄξω",
         ...
         ...

بلدي المحول. xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">

<TextView
    android:id="@+id/greek_word"
    android:layout_height="50dp"
    android:gravity="center_vertical"
    android:text="text"
    android:textSize="12dp"
    android:padding="3dp"
    android:visibility="visible"
    android:layout_width="fill_parent"
    android:textColor="#FF000000"
    android:background="#FFFFFFFF" />

build.gradle تحت SRC يجب أن تكون هذه المجموعة التلقائية UT8 ...

tasks.withType(Compile) {
options.encoding = 'utf-8'

}

تحرير: مشكلة حل بواسطة

!!!!!!!!!!!!!!!!! استخدم أوقات المحرف الجديدة roman.ttf وتطبيق على TextView عن طريق تجاوز طريقة المحول !!! !!!!!!!!!!!!!!!!!

font = Typeface.createFromAsset(getAssets(), "times.ttf");

ثم فقط قم بعمل كائن من هذه الفئة A راجعه إلى ListAdapter

 public class MyAdapter extends ArrayAdapter<String> {
    public Context context;
    public String[] values;
    private Typeface font;

    public MyAdapter(Context context, String[] values, Typeface font) {
        super(context, R.layout.adapteritem, values);
        this.context = context;
        this.values = values;
        this.font = font;
    }

    @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.adapteritem, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.greek_word);

        textView.setTypeface(font);
        textView.setText(values[position]); // maybe not the best line of code but i dont know how do it better.. but works :)

        return rowView;
    }
}
هل كانت مفيدة؟

المحلول

ربما لا يحفظ المحرر (Eclipse) الملفات كـ UTF-8؟

على أي حال ، يجب تخزين هذه السلاسل موارد سلسلة Android. نظرًا لأن هذه الملفات هي ملفات XML ، فمن غير المرجح أن تواجه مشاكل ترميز.

تحرير: حتى في Android Studio ، يمكنك الحصول على هذه المشكلة. يمكنك التحقق من ذلك هنا:enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top