我正在下載字體文件,當文件被下載時,我使用該文件作爲自定義字體。但是,當第1行更新時,它也會更新第8行,反之亦然。我嘗試了所有的方法,但我無法解決。下面是getView的代碼。請幫我解決這個問題。
在此先感謝。
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if(convertView == null) {
Log.d("inside value", position + "");
holder = new ViewHolder();
view = inflater.inflate(R.layout.sub_family_item, null);
holder.subVariantText = (TextView) view.findViewById(R.id.sub_family_style_text);
holder.subTextStyle = (TextView) view.findViewById(R.id.text_style);
holder.progressBar = (ProgressBar) view.findViewById(R.id.progress_bar_id);
view.setTag(holder);
}
else
{
holder = (ViewHolder) view.getTag();
}
SubFont fontStyle = getItem(position);
if(fontStyle != null)
{
holder.subVariantText.setText(fontStyle.getSubList());
holder.subTextStyle.setText(fontStyle.getFontStyleText());
}
File file = new File(FontConstant.folder+"/fontFile" + selectedPosition + position + ".ttf");
if(file.exists() && file.length() == this.fileSize)
{
TextView textView = (TextView) view.findViewById(R.id.text_style);
holder.progressBar.setVisibility(View.INVISIBLE);
Typeface custom_font = Typeface.createFromFile(file);
holder.subTextStyle.setTypeface(custom_font);
holder.subTextStyle.setVisibility(View.VISIBLE);
}
return view;
}
static class ViewHolder
{
TextView subVariantText;
TextView subTextStyle;
ProgressBar progressBar;
}
holder.subTextStyle.setTypeface(..)將導致修改視圖屬性。但是由於視圖被重用,它將應用於這個特定視圖被回收的行(作爲convertView)..現在,如果您只想應用於特定行,那麼您必須編寫其他case來將typeFace更改爲normal,所以,當視圖重新循環,它得到正常的行爲 – Aun 2014-11-04 05:58:40