xeoh/TextHighlighter

Issue while scrolling up and down multiple times

sweety000 opened this issue · 8 comments

Hi,
This is sweety, working as junior android developer. I have used the library, here the problem is when i scroll first time it is nice, but when i scroll next time from bottom to top with out changing the search text or with changing also the scrolling gets very slow. i did not get the reason for that.

I have fixed this issue by calling textHighlighter.resetTargets() method everytime before calling textHighlighter.invalidate(matcher);

xeoh commented

@sweety000 Thanks for pointing it out. Feel free to make a pull requeset. I'll deal with it asap.

xeoh commented

@sweety000 Can you post your code? I think being slow is caused by calling invalidate in wrong place.

@OverRide
public View getView(int position, View convertView, ViewGroup parent) {
Context context = parent.getContext();

  if (convertView == null) {
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.list_view_item, parent, false);
  }

  TextView nameTextView = (TextView) convertView.findViewById(R.id.name);
  nameTextView.setText(quotes.get(position).getKey());

  TextView quoteTextView = (TextView) convertView.findViewById(R.id.quote);
  quoteTextView.setText(quotes.get(position).getValue());
   
    textHighlighter.addTarget(quoteTextView);
    textHighlighter.invalidate(matcher);


  return convertView;
}
xeoh commented

@sweety000
Try to add targets when the convertView is inflated not on recycling. You are adding a same target multiple times.

if (convertView == null) {
  LayoutInflater inflater =
      (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  convertView = inflater.inflate(R.layout.list_view_item, parent, false);
  TextView quoteTextView = (TextView) convertView.findViewById(R.id.quote);
  // This is when the view created
  textHighlighter.addTarget(quoteTextView);
}

TextView nameTextView = (TextView) convertView.findViewById(R.id.name);
nameTextView.setText(quotes.get(position).getKey());

TextView quoteTextView = (TextView) convertView.findViewById(R.id.quote);
quoteTextView.setText(quotes.get(position).getValue());
   
textHighlighter.invalidate(matcher);

return convertView;

I didn't test the code but only imagine. Tell me if it doesn't solve the problem.

if ( !textViews.contains(quoteTextView)) { textViews.add(quoteTextView); textHighlighter.addTarget(quoteTextView); } textHighlighter.invalidate(matcher);

I wrote condition like this. I am not adding same target everytime, but still getting same issue.

xeoh commented

@sweety000 Ok. I'll tag you if I solve the problem.

xeoh commented

@sweety000
Sorry for late. Can you try with the new version?
Latest is 1.0.3.