You can use spans for this.
Let's assume you have a TextView
called myText
.
Drawable goButtonDrawable = getResources().getDrawable(R.drawable.go_button);
String text = "If you have good endurance, for killing the monster you must go to section 2. [GO]"
String replace = "[GO]";
final int index = text.indexOf(replace);
final int endIndex = index + replace.length();
final ImageSpan imageSpan = new ImageSpan(goButtonDrawable, ImageSpan.ALIGN_BASELINE);
final ClickableSpan clickSpan = new ClickableSpan() {
@Override public void onClick(View clicked) {
// Do your [GO] action
}
};
SpannableString spannedText = new SpannableString(text);
spannedText.setSpan(imageSpan, index, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannedText.setSpan(clickSpan, index, endIndex , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
myText.setText(spannedText);
Obviously this could be better abstracted (you could just make a custom TextView that handles this internally), but that's the general idea.