I am trying to put color and bold up on a word that matches the word from a sentence in ArrayList items/value. what I have done so far is as below... so I have a String variable called filter "Hello" now I want to iterate through ArrayList itemList and find "Hello" from ArrayList items and make it bold and blue.
String filter = "Hello";
String itemValue = "I just want to say Hello world! Hello";
itemList = new ArrayList<String>();
for(int i = 0; i<10; i++)
{
itemList.add("I just want to say Hello world! Hello");
}
sentence = new ArrayList<String>();
for(int j=0; j<itemList.size(); j++)
{
int startPos = itemList.get(j).toString().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);
tv.setText(spannable);
sentence.add(itemValue);
ListView lv = (ListView)findViewById(R.id.listView1);
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
// android.R.layout.simple_list_item_1, android.R.id.text1, sentence);
MyPerformanceArrayAdapter adapter = new MyPerformanceArrayAdapter(this, spannable, counterArrayList);
lv.setAdapter(adapter);
}
else
tv.setText(itemValue);
}
its not working can you please help me