0

Description:

I am downloading font file and when file is downloaded i am using that file as a custom font. But when row 1 is updated it also update row 8 and vice-versa. I have try all the ways but i am unable to solve. Code of getView is below. Please help me to solve this issue.

Thanks in advance.

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(..) will result in modifying the view properties. But since views are reused, it will apply to the rows where this specific view is recycled(comes as convertView).. now if you want to apply only for specific row, then you have to write else case to change the typeFace to normal, so that when the views are re-cylced, it gets normal behaviour – Aun Nov 04 '14 at 05:58

4 Answers4

1

You need to add the else statement in your getView :

if(fontStyle != null)
{
    holder.subVariantText.setText(fontStyle.getSubList());
    holder.subTextStyle.setText(fontStyle.getFontStyleText());
}
else
{
   //what should this row display if fontStyle  is null?
}

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);
}
else
{
   //what should this row display if the file is not exist?
}
Blaze Tama
  • 10,828
  • 13
  • 69
  • 129
1

add the data to your collection of data that is passed to your adapter

then call

 listView.notifyDataSetChanged();

thats it.

0

Use below code :-

myListView.invalidateViews();

or

myListView.notifyDataSetChanged();

See below answer for more info :-

How to refresh Android listview?

Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113
0

try like this may help you,

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if(convertView == null) {
        Log.d("inside value", position + "");
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.sub_family_item, null, false);
        holder.subVariantText = (TextView) convertView.findViewById(R.id.sub_family_style_text);
        holder.subTextStyle = (TextView) convertView.findViewById(R.id.text_style);
        holder.progressBar = (ProgressBar) convertView.findViewById(R.id.progress_bar_id);

       convertView.setTag(holder);
    }
    else
    {
        holder = (ViewHolder) convertView.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)
    {
        holder.progressBar.setVisibility(View.INVISIBLE);
        Typeface custom_font = Typeface.createFromFile(file);
        holder.subTextStyle.setTypeface(custom_font);
        holder.subTextStyle.setVisibility(View.VISIBLE);
    } else{
       holder.subTextStyle.setVisibility(View.GONE);
    }
    return convertView;
}

static class ViewHolder
{
    TextView subVariantText;
    TextView subTextStyle;
    ProgressBar progressBar;
}

i hope it will help you

Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19
  • Actually i am downloading different font size and once file downloaded i want to show the font style. By using your code at a time it show only one font style as you set visibility to be gone. Hope you understand my question. – Aniruddha07 Nov 04 '14 at 06:27