Skip to content

Instantly share code, notes, and snippets.

@yujuwon
Created June 27, 2016 02:40
Show Gist options
  • Select an option

  • Save yujuwon/41433dfa2e58c121fdc20c090908392f to your computer and use it in GitHub Desktop.

Select an option

Save yujuwon/41433dfa2e58c121fdc20c090908392f to your computer and use it in GitHub Desktop.
public class Hashtag extends ClickableSpan {
public interface ClickEventListener{
void onClickEvent(String data);
}
private ClickEventListener mClickEventListener = null;
private Context context;
private TextPaint textPaint;
public Hashtag(Context ctx){
super();
context = ctx;
}
public void setOnClickEventListener(ClickEventListener listener){
mClickEventListener = listener;
}
@Override
public void updateDrawState(TextPaint ds) {
textPaint = ds;
ds.setColor(ds.linkColor);
ds.setARGB(255, 30, 144, 255);
}
@Override
public void onClick(View widget) {
TextView tv = (TextView) widget;
Spanned s = (Spanned) tv.getText();
int start = s.getSpanStart(this);
int end = s.getSpanEnd(this);
String theWord = s.subSequence(start + 1, end).toString();
mClickEventListener.onClickEvent(theWord);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment