0

カスタムアダプターTextViewで使用しているカスタムがあります。GridViewカスタムTextViewは、翻訳目的でカスタム フォントを使用しています。これは、デフォルトでロケールがインストールされているデバイスでかなりうまく機能します。

ただし、言語がインストールされていないデバイスでは、奇妙な動作が表示されます。アプリが初めて読み込まれるとき、TextViewsカスタム フォントで表示されません。ただし、更新ボタンを押してフラグメントをリロードするTextViewsと、カスタムフォントで表示されます。

なぜこれが起こっているのかわかりません。

Adaptersこれは、カスタムを使用しているアプリケーションのすべてのカスタムで発生していますTextView

かなり基本的なアダプター:

public class CalendarWeekAdapter extends BaseAdapter{

    private String[] weekdays;
    Context mContext;
    private LayoutInflater mInflater;

       public CalendarWeekAdapter(Context context, int firstDay)
       {
              mContext=context;
              mInflater = LayoutInflater.from(context);
              weekdays = context.getResources().getStringArray(R.array.weekdays); 
       }
       public int getCount()
       {
              return weekdays.length;
       }
       public Object getItem(int position)
       {
              return position;
       }
       public long getItemId(int position)
       {
              return position;
       }
       public View getView(int position, View convertView, ViewGroup parent)
       {
              ViewHolder holder=null;
              if(convertView==null)
              {
                     convertView = mInflater.inflate(R.layout.calendar_week, parent,false);
                     holder = new ViewHolder();
                     holder.txtWeekdays=(CustomTextView)convertView.findViewById(R.id.weekdays);
                     if(position==0)
                     {                             
                           convertView.setTag(holder);
                     }
              }
              else
              {
                     holder = (ViewHolder) convertView.getTag();
              }


             holder.txtWeekdays.setText(weekdays[position]);


             return convertView;
       }

}
class ViewHolder
{        
          CustomTextView txtWeekdays;                 
}

基本的な CustomTextView:

public class CustomTextView extends TextView {
        public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init();
        }

        public CustomTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }

        public CustomTextView(Context context) {
            super(context);
            init();
        }

        private void init() {
            if (!isInEditMode()) {
                setTypeface(Utils.getFont(getContext()));
            }
        }
}
4

1 に答える 1

1

これは答えではないかもしれませんが、私はこのifステートメントを理解していません:

                 holder.txtWeekdays=(CustomTextView)convertView.findViewById(R.id.weekdays);
                 if(position==0)
                 {                             
                       convertView.setTag(holder);
                 }

なぜそこにあるのですか?新しく膨らませたすべての convertViews には、タグとして holder が必要です。convertView.setTag(holder) の周りの「if」を削除するだけです。

          if(convertView==null)
          {
                 convertView = mInflater.inflate(R.layout.calendar_week, null,false);
                 holder = new ViewHolder();
                 holder.txtWeekdays=(CustomTextView)convertView.findViewById(R.id.weekdays);
                 convertView.setTag(holder);
          }
          ...

これにより状況が改善されるか、さらには修正されるかどうかを確認してください。

于 2013-02-06T23:30:43.273 に答える