title: how do I highlight the searched text in my search filter?
body: <p>I am trying to do a search such that all the "visible" search letters should be highlighted. I tried using spannable but that didn't do the trick, maybe I wasnt doing it right? based on this: <a href="https://stackoverflow.com/questions/23905028/highlight-searched-text-in-listview-items">Highlight searched text in ListView items</a>
  How do i get to highlight the visible text? here's my filter :</p>
  
  <pre><code>private LayoutInflater mInflater;
  
          private ValueFilter valueFilter;
  
          public MySimpleArrayAdapter(Activity context) {
  
              this.context = context;
              mInflater = LayoutInflater.from(context);
  
          }
          private class ValueFilter extends Filter {
  
  
              //Invoked in a worker thread to filter the data according to the constraint.
              @Override
              protected synchronized FilterResults performFiltering(CharSequence constraint) {
  
                  FilterResults results = new FilterResults();
  
                  if (constraint != null &amp;&amp; constraint.length() &gt; 0) {
  
                      ArrayList&lt;Integer&gt; filterList = new ArrayList&lt;&gt;();
  
                      int iCnt = listItemsHolder.Names.size();
                      for (int i = 0; i &lt; iCnt; i++) {
                          if(listItemsHolder.Types.get(i).toString().indexOf("HEADER_")&gt;-1){
                              continue;
                          }
                          if (listItemsHolder.Names.get(i).matches(getRegEx(constraint))||(listItemsHolder.Names.get(i).toLowerCase().contains(constraint.toString().toLowerCase()))) {
                              if(filterList.contains(i))
                                  continue;
  
                              filterList.add(i);
  
                          }
                          }
  
                      results.count = filterList.size();
  
                      results.values = filterList;
                  }else {
                  String prefixString = getRegEx(constraint);
                  mSearchText = prefixString;
                      results.count = listItemsHolder.Names.size();
  
                      ArrayList&lt;Integer&gt; tList = new ArrayList&lt;&gt;();
                      for(int i=0;i&lt;results.count;i++){
                          tList.add(i);
                      }
  
                      results.values = tList;
  
                  }
  
                  return results;
  
  
  }
  
  
                  //Invoked in the UI thread to publish the filtering results in the user interface.
                  @SuppressWarnings("unchecked")
                  @Override
                  protected void publishResults(CharSequence constraint, FilterResults results) {
                      ArrayList&lt;Integer&gt; resultsList = (ArrayList&lt;Integer&gt;)results.values;
                      if(resultsList != null) {
                          m_filterList = resultsList;
                      }
                      notifyDataSetChanged();
                  }
  
              }
  
              public String getRegEx(CharSequence elements){
                  String result = "(?i).*";
                  for(String element : elements.toString().split("\\s")){
                      result += element + ".*";
                  }
                  result += ".*";
                  return result;
              }
  
  Thanks in advance! 
  </code></pre>
  
  <p>Here's my getview</p>
  
  <pre><code>@Override
          public View getView(int position, View convertView, ViewGroup parent) {
              View rowView = convertView;
              ViewHolder holder;
              if(filtering &amp;&amp; m_filterList != null &amp;&amp; m_filterList.size() &gt; position)
                  position = m_filterList.get(position);
  
              if (rowView == null) {
                  holder = new ViewHolder();
  
                  mInflater = context.getLayoutInflater();
                  rowView = mInflater.inflate(R.layout.rowlayout, null);
                  // configure view holder
                  holder.text = (TextView) rowView.findViewById(R.id.label);
                  holder.text.setTextColor(Color.WHITE);
                  holder.text.setSingleLine();
                  holder.text.setTextSize(15);
                  holder.text.setEllipsize(TextUtils.TruncateAt.END);
                  holder.text.setPadding(2, 2, 6, 2);
                  Typeface label = Typeface.createFromAsset(holder.text.getContext().getAssets(),
                          "fonts/arial-bold.ttf");
                  holder.text.setTypeface(label);
                  holder.image = (ImageView) rowView.findViewById(R.id.icon);
                  holder.image.setPadding(6, 4, 0, 4);
                  holder.image.getLayoutParams().height = (int) getResources().getDimension(R.dimen.icon_width_height);
                  holder.image.getLayoutParams().width = (int) getResources().getDimension(R.dimen.icon_width_height);
                  rowView.setBackgroundResource(R.drawable.row_border);
                  rowView.setPadding(2, 2, 6, 2);
                  rowView.setTag(holder);
              }else {
  
                  // fill data
                  holder = (ViewHolder) rowView.getTag();
              }
  
              String id  = listItemsHolder.getid(position);
              String name = listItemsHolder.getName(position);
              holder.image.setVisibility(View.VISIBLE);
  
  
              if (name != null) {
                  holder.text.setText(listItemsHolder.getName(position));
                  ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) holder.text.getLayoutParams();
                  params.leftMargin = 20;
              }else{
                  holder.text.setText(id);
              }
              String fullText = listItemsHolder.getName(position);
              // highlight search text
              if (mSearchText != null &amp;&amp; !mSearchText.isEmpty()) {
                  int startPos = fullText.toLowerCase(Locale.US).indexOf(mSearchText.toLowerCase(Locale.US));
                  int endPos = startPos + mSearchText.length();
                  if (startPos != -1) {
                      Spannable spannable = new SpannableString(fullText);
                      ColorStateList blueColor = new ColorStateList(new int[][]{new int[]{}}, new int[]{Color.BLUE});
                      TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, blueColor, null);
                      spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                      holder.text.setText(spannable);
                  } else {
                      holder.text.setText(fullText);
                  }
              } else {
                  holder.text.setText(fullText);
              }
              return rowView;
          }
  </code></pre>