データを表示するためのテキストビューを持つカスタムリストビューがあり、ビューホルダーパターンを使用してメモリ使用量を最適化していますが、リストビューを連続してスクロールすると、 android studio内)リストビューのメモリ使用量
問題をどのように解決すればよいですか?
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewContainer viewContainer;
View rowView = view;
if(rowView==null){
LayoutInflater inflater = context.getLayoutInflater();
rowView= inflater.inflate(R.layout.lv2rowlayout, null, true);
viewContainer = new ViewContainer();
//---get a reference to all the views on the xml layout---
viewContainer.txten = (TextView) rowView.findViewById(R.id.txten);
viewContainer.txtfars = (TextView) rowView.findViewById(R.id.txtfars);
String s ;
Typeface custom_font;
viewContainer.txten.setTextSize(TypedValue.COMPLEX_UNIT_SP,sd.enSize);
s="fonts/"+sd.enFont;
custom_font = Typeface.createFromAsset(context.getAssets(),s);
viewContainer.txten.setTypeface(custom_font);
viewContainer.txten.setTextColor(sd.enColor);
viewContainer.txtfars.setTextSize(TypedValue.COMPLEX_UNIT_SP,sd.farssize);
s="fonts/"+sd.farsFont;
custom_font = Typeface.createFromAsset(context.getAssets(),s);
viewContainer.txtfars.setTypeface(custom_font);
viewContainer.txtfars.setTextColor(sd.farsColor);
rowView.setTag(viewContainer);
}
else {
viewContainer = (ViewContainer) rowView.getTag();
}
//---customize the content of each row based on position---
viewContainer. txten.setText(en[position]);
viewContainer.txtfars.setText(fars[position]);
return rowView;
}
あなたの書体は位置に依存しないので、グローバル変数を宣言してリストビューのコンストラクタで初期化するのはなぜですか? – Kaustuv
はいこれは本当の意味です –