Comments (3)
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.
- Create global variable :
private CharSequence search_txt = "";
- Edit performFiltering method by adding the following right at the beginning :
search_txt = constraint;
- 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.
JazakAllahu khayran.
UPDATE
Issue has been re-opened. Future iterations should work for recyclerView.
from hisnulmuslim.
Related Issues (20)
- Actionbar/toolbar has no drop shadow pre-Lollipop HOT 1
- App crashes when scrolling long list HOT 1
- Actionbar font size in Landscape orientation
- Crash when tap Search result on 4.4.2 (KitKat) HOT 1
- Font choice preference bug HOT 1
- Dua Content list
- Dua Group number and Dua Group title in Toolbar HOT 1
- Duplicate dua under group #1 : Waking up HOT 1
- Text in Search list is no longer highlighted
- Arabic tashkeel not appearing properly on 4.1.2 HOT 1
- Sharing dua to Facebook app results in blank post HOT 1
- RecyclerView in BookmarksDetail activity has rigid scroll bars
- In-app Search is ugly and disfunctional
- Dua group number is cut off
- I want to publish this application on Google Play Store. HOT 4
- Arabic font line height, and overlapping characters HOT 1
- Change dua language depending on phone's locale
- Any update? HOT 2
- Invalid SQL query: table not found
- What is the license for this project ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hisnulmuslim.