I working on module to search grab text from edit text and search it into current text view. If present highlight this text in current text view. I also googled for this code but didn't found any relevant answer.
tv=(TextView) mView.findViewById(R.id.detailsText);
edit_text=(EditText)findViewById(R.id.searchText);
edit_text.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
hightLightText(tv, s.toString());
}
});
}
void hightLightText(TextView textView, String searchString){
try{
String s=getResources().getString(R.string.firstpage);
String withHighLightedText = s.replaceAll(searchString, "<font color='red'>"+searchString+"</font>");
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(withHighLightedText), TextView.BufferType.SPANNABLE);
}catch(Exception ex){
}
}