i have a 3 String like this:
"@Username: Deliverd your order",
"YOU got trophy: KING OF COINS",
"There is a package waiting for you to pick up from #surat to #mumbai",
what i wanted to do is get username and city name in different color with its click event.
what i m able to achive is get username by splitting to ":" character. but i dont know how to get city name and click event of both.
In city name only last city color is changing, how to change both city name color and get its click event.
this is what i tried:
if (notifications.getTitle().contains(":"))
{
String[] username = notifications.getTitle().split(":");
String uname = getColoredSpanned(username[0] + ":", "#ff7505");
String txt = getColoredSpanned(username[1], "#000000");
holder.txtTitle.append(Html.fromHtml(uname +" " + txt));
holder.txtTitle.setMovementMethod(LinkMovementMethod.getInstance());
}
else if (notifications.getTitle().contains("#"))
{
Matcher matcher =
Pattern.compile("#\\s(\\w+)").matcher(notifications.getTitle());
i=0;
while (matcher.find())
{
place.add(i, matcher.group(1));
i++;
}
String place1 = getColoredSpanned("#" + place.get(0), "#237BCD");
String place2 = getColoredSpanned("#" + place.get(1), "#237BCD");
places1 = notifications.getTitle().replace("#" + place.get(0), place1);
places1 = notifications.getTitle().replace("#" + place.get(1), place2);
holder.txtTitle.setText(Html.fromHtml(places1));
}
else
{
holder.txtTitle.setText(notifications.getTitle());
}
private String getColoredSpanned(String text, String color) {
String input = "<font color=" + color + ">" + text + "</font>";
return input;
}
and this is what i get as output:
and this is what i really expected: