GithubHelp home page GithubHelp logo

Comments (3)

khalid-hussain avatar khalid-hussain commented on July 30, 2024

The following StackOveflow question seems to give a hint but I don't see how I can fit it into the current code:
Highlight searched text in ListView items

from hisnulmuslim.

mdali92 avatar mdali92 commented on July 30, 2024
  1. Create global variable :
   private CharSequence search_txt = "";
  1. Edit performFiltering method by adding the following right at the beginning :
  search_txt = constraint;
  1. Finally, edit getView method by adding the following lines :
        holder.tvDuaName.setText(p.getTitle());
        //highlight(search_txt.toString(),holder.tvDuaName.getText().toString());
        String filter = search_txt.toString();
        String itemValue = holder.tvDuaName.getText().toString();

        int startPos = itemValue.toLowerCase(Locale.US).indexOf(filter.toLowerCase(Locale.US));
        int endPos = startPos + filter.length();

        if (startPos != -1) // This should always be true, just a sanity check
        {
            Spannable spannable = new SpannableString(itemValue);
            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.tvDuaName.setText(spannable);
        }
        else
            holder.tvDuaName.setText(itemValue);

P.S : There is one correction. In the if else statement right after the line :

            ViewHolder holder;

After you have completed the "if" part, you forgot to add the "else" and have begun without it. Add the "else" otherwise the logic is wrong.

from hisnulmuslim.

khalid-hussain avatar khalid-hussain commented on July 30, 2024

JazakAllahu khayran.

UPDATE
Issue has been re-opened. Future iterations should work for recyclerView.

from hisnulmuslim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.